I have this problem:
I have a method
private XmlElement ToXmlElement(string xml)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
return doc.DocumentElement;
}
And my input xml string is:
<?xml version="1.0"?>
<Collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:IEEE-1671:2009.02:Common">
<Item name="edsw">
<Collection />
</Item>
</Collection>
I need to return from this string XmlElement, which looks like:
<Collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:IEEE-1671:2009.02:Common">
<Item name="edsw">
<Collection />
</Item>
</Collection>
thats everything without <?xml version ="1.0"?>
but doc.DocumentElements returns me only:
<Item name="edsw" xmlns="urn:IEEE-1671:2009.02:Common">
<Collection />
</Item>
is there any way how to achieve it?
DocumentElementreturns the wholeCollection. How are you converting the result to string?ToStringElement(ToXmlElement(xml))returns the wholeCollection. That meansToXmlElement()actually does what you want it to do.