Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Writing Dataset to XML corrupts XML file

Writing Dataset to XML corrupts XML file

Scheduled Pinned Locked Moved C#
csharpxmlannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reanalyse
    wrote on last edited by
    #1

    I am having a lot of issues with this in VS2003 - programming in C# I am trying to update one field in an XML file using a dataset The code for the updating is _______________________________________________________________ // get the selected row DataRow selectedRow = contacts.Tables[0].Rows[contactlist.SelectedIndex]; // Begin an edit transaction on the row. selectedRow.BeginEdit(); selectedRow["Service_Release_SQL"] =sr_sql.Text; selectedRow.EndEdit(); contacts.WriteXml(@"contacts.xml"); ______________________________________________________________ where "contactlist.SelectedIndex" gives me the XML row to update, and the field in that row is called "Service_Release_SQL" This complies OK, and runs without throwing an exception but the result always is that my XML file loses all field after the "Service_Release_SQL" field. Can anyone indicate where I am going wrong Thank you for your time

    K 1 Reply Last reply
    0
    • R Reanalyse

      I am having a lot of issues with this in VS2003 - programming in C# I am trying to update one field in an XML file using a dataset The code for the updating is _______________________________________________________________ // get the selected row DataRow selectedRow = contacts.Tables[0].Rows[contactlist.SelectedIndex]; // Begin an edit transaction on the row. selectedRow.BeginEdit(); selectedRow["Service_Release_SQL"] =sr_sql.Text; selectedRow.EndEdit(); contacts.WriteXml(@"contacts.xml"); ______________________________________________________________ where "contactlist.SelectedIndex" gives me the XML row to update, and the field in that row is called "Service_Release_SQL" This complies OK, and runs without throwing an exception but the result always is that my XML file loses all field after the "Service_Release_SQL" field. Can anyone indicate where I am going wrong Thank you for your time

      K Offline
      K Offline
      KaptinKrunch
      wrote on last edited by
      #2

      Should consult MSDN for this one, copied from there. You may be missing parts of this. private void WriteXmlToFile(DataSet thisDataSet) { // Create a file name to write to. string filename = "myXmlDoc.xml"; // Create the FileStream to write with. System.IO.FileStream myFileStream = new System.IO.FileStream (filename, System.IO.FileMode.Create); // Create an XmlTextWriter with the fileStream. System.Xml.XmlTextWriter myXmlWriter = new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode); // Write to the file with the WriteXml method. thisDataSet.WriteXml(myXmlWriter); myXmlWriter.Close(); }

      R 1 Reply Last reply
      0
      • K KaptinKrunch

        Should consult MSDN for this one, copied from there. You may be missing parts of this. private void WriteXmlToFile(DataSet thisDataSet) { // Create a file name to write to. string filename = "myXmlDoc.xml"; // Create the FileStream to write with. System.IO.FileStream myFileStream = new System.IO.FileStream (filename, System.IO.FileMode.Create); // Create an XmlTextWriter with the fileStream. System.Xml.XmlTextWriter myXmlWriter = new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode); // Write to the file with the WriteXml method. thisDataSet.WriteXml(myXmlWriter); myXmlWriter.Close(); }

        R Offline
        R Offline
        Reanalyse
        wrote on last edited by
        #3

        Thanks I suspect that my trouble is that the dataset is "set" to a different XML schema that the file being loaded (a previous version of the XML file), hence ignoring the columns after the ones it "knows about". I suspect I will need to specifically load the schema, and save the schema as well as the data. Will try it out on Monday when I get back to the office

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups