469,627 Members | 936 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

DataSet.WriteXML writes strange node names, why?

This code,
DS1 = new DataSet("DataSet 1");
DataTable dt1 = new DataTable("Table 1");
DataColumn dc1 = new DataColumn("Column 1",
typeof(String));
DataColumn dc2 = new DataColumn("Column 2",
typeof(String));
dt1.Columns.AddRange(new DataColumn[] { dc1, dc2 });
dt1.Rows.Add(new string[] { "A", "B" });
dt1.Rows.Add(new string[] { "C", "D" });
DS1.Tables.Add(dt1);
DS1.WriteXml("test.xml");
creates an xml like,
<?xml version="1.0" standalone="yes"?>
<DataSet_x0020_1>
<Table_x0020_1>
<Column_x0020_1>A</Column_x0020_1>
<Column_x0020_2>B</Column_x0020_2>
</Table_x0020_1>
<Table_x0020_1>
<Column_x0020_1>C</Column_x0020_1>
<Column_x0020_2>D</Column_x0020_2>
</Table_x0020_1>
</DataSet_x0020_1>
Why is this? Of course I expected "Column 1", instead of
"Column_x0020_1". I could not figure out the reason, please give me a
hint. Thanks.
Jan 26 '08 #1
3 3072
You have space characters imbedded in the names you have provided for your
Dataset, DataTable and DataColumns.

XML does not allow a space character in an element name and therefore, the
code behind the WriteXml method has written a hex representation of your
space characters so that the element names are legal.
"Sin Jeong-hun" <ty*******@gmail.comwrote in message
news:4d**********************************@h11g2000 prf.googlegroups.com...
This code,
DS1 = new DataSet("DataSet 1");
DataTable dt1 = new DataTable("Table 1");
DataColumn dc1 = new DataColumn("Column 1",
typeof(String));
DataColumn dc2 = new DataColumn("Column 2",
typeof(String));
dt1.Columns.AddRange(new DataColumn[] { dc1, dc2 });
dt1.Rows.Add(new string[] { "A", "B" });
dt1.Rows.Add(new string[] { "C", "D" });
DS1.Tables.Add(dt1);
DS1.WriteXml("test.xml");
creates an xml like,
<?xml version="1.0" standalone="yes"?>
<DataSet_x0020_1>
<Table_x0020_1>
<Column_x0020_1>A</Column_x0020_1>
<Column_x0020_2>B</Column_x0020_2>
</Table_x0020_1>
<Table_x0020_1>
<Column_x0020_1>C</Column_x0020_1>
<Column_x0020_2>D</Column_x0020_2>
</Table_x0020_1>
</DataSet_x0020_1>
Why is this? Of course I expected "Column 1", instead of
"Column_x0020_1". I could not figure out the reason, please give me a
hint. Thanks.
Jan 26 '08 #2
On Jan 26, 11:44*am, "Stephany Young" <noone@localhostwrote:
You have space characters imbedded in the names you have provided for your
Dataset, DataTable and DataColumns.

XML does not allow a space character in an element name and therefore, the
code behind the WriteXml method has written a hex representation of your
space characters so that the element names are legal.

"Sin Jeong-hun" <typing...@gmail.comwrote in message

news:4d**********************************@h11g2000 prf.googlegroups.com...
This code,
* * * * * *DS1 = new DataSet("DataSet 1");
* * * * * *DataTable dt1 = new DataTable("Table 1");
* * * * * *DataColumn dc1 = new DataColumn("Column 1",
typeof(String));
* * * * * *DataColumn dc2 = new DataColumn("Column 2",
typeof(String));
* * * * * *dt1.Columns.AddRange(new DataColumn[] { dc1, dc2 });
* * * * * *dt1.Rows.Add(new string[] { "A", "B" });
* * * * * *dt1.Rows.Add(new string[] { "C", "D" });
* * * * * *DS1.Tables.Add(dt1);
* * * * * *DS1.WriteXml("test.xml");
creates an xml like,
<?xml version="1.0" standalone="yes"?>
<DataSet_x0020_1>
* <Table_x0020_1>
<Column_x0020_1>A</Column_x0020_1>
<Column_x0020_2>B</Column_x0020_2>
* </Table_x0020_1>
* <Table_x0020_1>
<Column_x0020_1>C</Column_x0020_1>
<Column_x0020_2>D</Column_x0020_2>
* </Table_x0020_1>
</DataSet_x0020_1>
Why is this? Of course I expected "Column 1", instead of
"Column_x0020_1". I could not figure out the reason, please give me a
hint. Thanks.
Ah, thanks. I forgot XML node name cannot contain spaces.
Jan 26 '08 #3
</DataSet_x0020_1>

x0020 = 32 (base 10) = spacechar in ASCII... think?
//CY
Jan 26 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.