James

James

  • NA
  • 1
  • 0

DataSet XML

Nov 14 2007 11:11 AM
Hi,

I’m loading XML into a DataSet using the following…


// Create a new Customer DataSet.
CustomerDS = new DataSet();
// Get a handle to the Customer.xml file.
CustomerFileHandle = new FileStream(CUSTOMERXMLFILEPATH, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

// Read the Customer XML file into the DataSet.
CustomerDS.ReadXml(new XmlTextReader(CustomerFileHandle));

This loads the information into the DataSet and it can all be viewed on my Form.

After making changes to my data, I then want to update the XML file. To do this I’m using the following code…


XmlTextWriter CustXmlWriter = new XmlTextWriter(CustomerFileHandle, System.Text.Encoding.Unicode);
// Write to the file with the WriteXml method.
CustomerDS.WriteXml(CustXmlWriter, XmlWriteMode.IgnoreSchema);
CustXmlWriter.Close();
// Close the Customer XML File.
CustomerFileHandle.Close();

This is not producing valid XML. All data (the xml) is being repeated at the end of the file with a NULL character in between each character.

Any help on this would be much appreciated.

Thanks in advance.