I have wrote some utility methods for creating XmlDocument from XML string.
public static class XMLUtils { // xml string to XmlDocument public static XmlDocument ToXmlDocument(this string xml) { var doc = new XmlDocument(); doc.LoadXml(xml); return doc; } // XmlReader to XmlDocument // XMLReader is useful for read xml data from url source public static XmlDocument ToXmlDocument(this XmlReader reader) { var doc = new XmlDocument(); doc.Load(reader); return doc; } // path to xml file to XmlDocument public static XmlDocument ReadFromPath( string path) { return ToXmlDocument(File.ReadAllText(path)); } }
コメント