Tom Vukovich said:
ds.WriteXml(Response.OutputStream, XmlWriteMode.IgnoreSchema)
I would like to add
<?xml version="1.0" ?>
to the top of the response stream.
Well, for starters, have you tried,
new StreamWriter( Response.OutputStream).Write( "<?xml version=\"1.0\" ?>");
prior to calling ds.WriteXml( )?
If you want greater control over the XML output, then you should
wrap the DataSet in an XmlDataDocument. However, to manipulate
the XmlDataDocument's formatting you must turn off constraints in
the DataSet (presumably when rendering a response to an HTTP
request, the DataSet is about to go away just the same so this may
be acceptable).
XmlDataDocument xmlDoc = new XmlDataDocument( ds);
xmlDoc.DataSet.EnforceConstraints = false;
XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration( "1.0", null, null);
xmlDoc.PrependChild( xmlDecl);
xmlDoc.WriteTo( new XmlTextWriter( Response.OutputStream));
Advantages to this approach include the ability to do a number of
things to the XML output, including nicely indented and formatted
XML,
XmlDataDocument xmlDoc = new XmlDataDocument( ds);
xmlDoc.DataSet.EnforceConstraints = false;
XmlTextWriter xmlSink = new XmlTextWriter( Response.OutputStream);
xmlSink.Formatting = Formatting.Indented;
xmlSink.Indentation = 4;
xmlDoc.WriteTo( xmlSink);
Derek Harmon