Im trying to generate some valid xml from a SQL Server dataset.
I can get it to crank out the standard xml using WriteXml but I would like to add some elements and nodes before this part. Can I do this? Also can I modify the default tags that the WriteXML kicks out?
I have some code that I am trying to use to write start and end elements but it keeps saying invalid xml
// Build the DataSet
DataSet myDs = new DataSet();
adapter.Fill(myDs);
FileStream myFs = null;
// Get a FileStream object
myFs = new FileStream(filename+".xml", FileMode.OpenOrCreate, FileAccess.Write);
XmlTextWriter xmlWriter = new XmlTextWriter(myFs, Encoding.UTF8);
xmlWriter.Indentation = 85;
xmlWriter.Namespaces = false;
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Request");
myDs.WriteXml(xmlWriter,System.Data.XmlWriteMode.IgnoreSchema);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
// It is always good housekeeping to close a file.
myFs.Close();
I can get it to crank out the standard xml using WriteXml but I would like to add some elements and nodes before this part. Can I do this? Also can I modify the default tags that the WriteXML kicks out?
I have some code that I am trying to use to write start and end elements but it keeps saying invalid xml
// Build the DataSet
DataSet myDs = new DataSet();
adapter.Fill(myDs);
FileStream myFs = null;
// Get a FileStream object
myFs = new FileStream(filename+".xml", FileMode.OpenOrCreate, FileAccess.Write);
XmlTextWriter xmlWriter = new XmlTextWriter(myFs, Encoding.UTF8);
xmlWriter.Indentation = 85;
xmlWriter.Namespaces = false;
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Request");
myDs.WriteXml(xmlWriter,System.Data.XmlWriteMode.IgnoreSchema);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
// It is always good housekeeping to close a file.
myFs.Close();