dataset "WriteXml" format
I have a table ("ssn") in a dataset. I want to write the table to a xml file. When I call
Dataset ds = new Dataset("Demographics_Stats");
dataAdapter.Fill (ds, "ssn");
ds.Tables["ssn"].WriteXml(outputFilename);
the output file looks like this:
<?xml version="1.0" standalone="yes">
<Demographics_Stats>
<ssn>
<PersonID>0000023</PersonID>
</ssn>
<ssn>
<PersonID>0000035</PersonID>
</ssn>
</Demographics_Stats>
Is it possible that the output can look like this:
<?xml version="1.0" standalone="yes">
<Demographics_Stats>
<ssn>
<PersonID>0000023</PersonID>
<PersonID>0000035</PersonID>
</ssn>
</Demographics_Stats>
Thanks!
auhe
[838 byte] By [
auhe] at [2008-2-24]
It looks like the DataSet contains:
a DataTable "ssn" with 1 nested DataTable "PersonID" which has a SimpleContent DataColumn named PersonID_text. Given this schema, the WriteXml output is as expected.
There is very little that one can do to change the format, the only option is to change the XML format of an DataColumn to be attribute, Element or SimpleContent, this is not what you are looking for.
One possible way to get the desired XML output is by doing the following:
1. Create a standalone DataTable "ssn" with DataColumn name PersonID, ColumnMapping=ColumnMapping.SimpleContent.
2. Iterate over all rows in the PersonID DataTable and copy the contents of it's SimpleContent column to the new ssn DataTable.
3. WriteXml on the new ssn DataTable should give you the desired format.
Thanks,
Kawarjit Bedi
Program Manager - ADO.NET
kbedi@microsoft.com