473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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 3215
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LoF | last post by:
Hi, I am generating deeply nested XML document from a Dataset using ' Write to the file with the WriteXml method. DataSet21.WriteXml(myXmlWriter) The generated XML contains the <DataSet2>...
3
by: Bill C. | last post by:
Hi, I've got a simple console app that just reads an XML file into a DataSet then prints out a description of each table in the DataSet, including column names and row values for each column. ...
0
by: Nathan Ernst | last post by:
I have a pretty simple XSD schema: ******************************************** * XSD SCHEMA ******************************************** <?xml version="1.0" encoding="utf-8" ?> <xs:schema...
3
by: Joe98765 | last post by:
I have data coming from SQL Server and need to write out some XML. I have a schema(xsd) for this XML file. Right now I am bringing in the DataSet and writing out the elements and attributes myself...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.