Add a Root element to a loaded XmlDocument?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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...
 
Hi,

This would be a crude way, but works:

xd.LoadXml("<?xml version="1.0" encoding="iso-8859-1"?><Root>" + xd.OuterXml
+ "</Root>");
 
Back
Top