How can i remove preprocessing instructions from an XML in a greener way? suppose that I have this xml in a string
variable (which is a property of a class),I wante
If you can load it in an XmlDocument: FirstChild returns the <?xml version="1.0" encoding="utf-8" ?>
node, and NextSibling
returns the rest.
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.FirstChild.NextSibling;
Edit: Your xml looks a lot like the example on msdn for XPathNavigator.Select. Have you tried using that?
Edit2: You can get the name of the top level element using:
string topLevelNode = doc.DocumentElement.Name;
Try the code below. It will load the text to XmlDocument
object first
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlAsText);
Then you can get the OutherXml
using below:
xmlDoc.DocumentElement.OuterXml;