DataSet and XML problem

A

Amit Patankar

Hi,

I have an XML file having following format:

<Table1>
<Row1> Value </Row1>
<Table2>
<Row2>Value</Row2>
</Table2>
</Table1>

I read this xml file and corresponding XSD file using dataset. But when I
read the above xml file and rewrite the same contents, using WriteXML, i
get an extra node at the top. So the new xml file looks like this:

<Root>
<Table1>
<Row1> Value </Row1>
<Table2>
<Row2>Value</Row2>
</Table2>
</Table1>
</Root>

So an extra <Root> tag, which I found corresponds to the schema ID is added,
which is unwanted. I guess this should be the problem with the dataset.
Could anyone suggest what I can do to avoid this extra node?

Thanks a lot.
Amit.
 
I

Ilya Tumanov [MS]

This is by design. DataSet XML saver has added DataSet tag which was
missing from your original XML.
That tag allows saving more than one row to the XML (your original XML only
allows for one row):

Wrong:

<Table> << First row in the Table

</Table>
<Table> << Second row in the Table - Can't be here as it would
create an invalid XML document.

</Table>

Correct:

<DataSet>
<Table> << First row in the Table

</Table>
<Table> << Second row in the Table

</Table>
</DataSet>


Note DataSet is not the XML storage, it's in memory database. It saves data
to XML in a very specific format.
The fact you can load some XML into the DataSet does not mean you'll get it
back the same way it was.
It only means data in the DataSet will be the same regardless of which file
you would load.

Consider using XmlDocument class which is in memory representation of the
XML instead if you need to keep XML exactly as it was.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top