richzilla
richzilla

Reputation: 41992

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.

Upvotes: 1

Views: 162

Answers (2)

Jehof
Jehof

Reputation: 35544

The quickest way would be:

string pathToXmlFile = //your path;
XmlDocument document = new XmlDocument();
document.Load(pathToXmlFile);

Upvotes: 2

Jon Skeet
Jon Skeet

Reputation: 1500495

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.

Upvotes: 3

Related Questions