Quickest way to generate xmldocument object from xml file
whats the quickest way to generate an XmlDocument object from a file开发者_开发百科. Im working on the basis that i know my xml is well formed, and ideally im looking for a method that will allow me to simply pass in a string as my file location, and return a complete XmlDocument object.
Um, XmlDocument.Load
?
XmlDocument document = new XmlDocument();
document.Load(filename);
On the other hand, if you're using .NET 3.5 or higher you should strongly consider moving to LINQ to XML and XDocument
instead:
XDocument doc = XDocument.Load(filename);
LINQ to XML is a much nicer XML API.
The quickest way would be:
string pathToXmlFile = //your path;
XmlDocument document = new XmlDocument();
document.Load(pathToXmlFile);
精彩评论