How can I add an XML Declaration and root element to an XmlDocument after it
has been loaded?
Here is the code...
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText= "SELECT ID, Desc FROM products FOR XML AUTO, ELEMENT";
XmlReader xr = cmd.ExecuteXmlReader();
XmlDocument xd = new XmlDocument(xr);
xr.Close;
...at this point I would like to add an XML Declaration and root element
nodes, but I am unsure how...
Manoj G [MVP] - 26 Aug 2004 11:11 GMT
Hi,
This would be a crude way, but works:
xd.LoadXml("<?xml version="1.0" encoding="iso-8859-1"?><Root>" + xd.OuterXml
+ "</Root>");

Signature
HTH,
Manoj G
[MVP , Visual Developer - Visual Basic ]
http://msmvps.com/manoj/
> How can I add an XML Declaration and root element to an XmlDocument after it
> has been loaded?
[quoted text clipped - 9 lines]
> ...at this point I would like to add an XML Declaration and root element
> nodes, but I am unsure how...