ColumnMapping Difference in MappingType?

  • Thread starter Thread starter xenophon
  • Start date Start date
X

xenophon

What is the difference between a MapingType.Element and
MappingType.SimpleContent? The MSDN docs only seem to say "there is a
difference", but I can't tell because when I serialize my DataSet or
DataTable, they look the same. Using .NET Framework 2.0.

Thanks.
 
Hi,

Based on my test with the code below.
private void button2_Click(object sender, EventArgs e)
{
DataTable dataTable = new DataTable("MyTable");
DataColumn dc = new DataColumn();
dc.ColumnName = "MyColumnName";
dc.DataType = typeof(int);
dc.ColumnMapping = MappingType.SimpleContent;
//dc.ColumnMapping = MappingType.Element;
dataTable.Columns.Add(dc);
DataRow dr = dataTable.NewRow();
dr[0]=100;
dataTable.Rows.Add(dr);
foreach (DataColumn dataColumn in dataTable.Columns)
{
MessageBox.Show(dataColumn.ColumnMapping.ToString());
}
dataTable.WriteXml(@"C:\temp\test1.txt");
}


[SimpleContent]
<?xml version="1.0" standalone="yes"?>
<DocumentElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyTable>100</MyTable>
</DocumentElement>

[Element]
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<MyTable>
<MyColumnName>100</MyColumnName>
</MyTable>
</DocumentElement>

From the output, we will know that, in the SimpleContent mapping, the Text
"100" will be consider as a column. But in the Element, the
<MyColumnName>100</MyColumnName> is considered as a column.

Also here is a link for your reference.

Inferring Element Text
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconinferringelementtext.asp



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top