Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write xml problem - puts new items in wrong place

Status
Not open for further replies.

saroyal

Programmer
Jul 3, 2002
30
0
0
GB
I have read the following xml file into a dataset:

<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?>
<listsource xmlns=&quot; <listcount>3</listcount>
<lastUpdated>2004-02-18</lastUpdated>
<listitems>
<item itemID=&quot;1&quot; name=&quot;item 1&quot;></item>
<item itemID=&quot;2&quot; name=&quot;item 2&quot;></item>
<item itemID=&quot;3&quot; name=&quot;item 3&quot;></item>
</listitems>
</listsource>

Then in the dataset I have added a new row and also gone through the rows to check it is there. My problem is writing this data back to an xml file. I thought I could just use the dataset.WriteXml method but my xml file turns out like this:

<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?>
<listsource xmlns=&quot; <listcount>3</listcount>
<lastUpdated>2004-02-18</lastUpdated>
<listitems>
<item itemID=&quot;1&quot; name=&quot;item 1&quot;></item>
<item itemID=&quot;2&quot; name=&quot;item 2&quot;></item>
<item itemID=&quot;3&quot; name=&quot;item 3&quot;></item>
</listitems>
</listsource>
<item itemID=&quot;4&quot; name=&quot;new item 4&quot;></item>

Can I get the new item in the correct place or would I manually have to write the xml writing each element out to make sure it does it correctly?

Thanks

Simon
 
sounds like your xsd file is properly set up. Check to make sure the dataset schema (xsd) is formatted the way you want it.

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
It was my first real decnt go at using XML and indeed it was the XSD file. After defining a table relationship or so I finally got it to run correctly.

Thanks

Simon
 
glad you've got it.

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top