简体   繁体   中英

How do I create a DOM tree from an XML file in C#?

Can someone give me a direction as how I can create a DOM tree from an XML file in C#/WPF, if any one has had any experience with this, maybe what classes you've used? Any help would be appreciated.

You can use the XmlDocument class for loading your XML File into a DOM.

MSDN - This class implements the W3C Document Object Model (DOM) Level 1 Core and the Core DOM Level 2. The DOM is an in-memory (cache) tree representation of an XML document and enables the navigation and editing of this document. Because XmlDocument implements the IXPathNavigable interface it can also be used as the source document for the XslTransform class.

More Information

LINQ to XML works great for this; I find it much easier to use than the DOM. Try:

XDocument doc = XDocument.Load("PurchaseOrder.xml");
Console.WriteLine(doc);

使用XmlDocumentSystem.Xml )类或XDocumentSystem.Xml.Linq )类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM