Share via


XML Processing Options in the .NET Framework

The XML classes in the .NET Framework represent a coherently designed and integrated set of classes that enable you to build XML-aware applications easily. These classes help developers address real-world issues not only in building Web-orientated applications, but in all other areas where XML is used

In-Memory XML Processing

The .NET Framework provides three options for processing XML data in-memory: LINQ to XML, the XPathNavigator class, and the XmlDocument class.

LINQ to XML

LINQ to XML provides an interface for accessing XML data that is comparable to an updated, redesigned DOM interface. LINQ to XML leverages the .NET Language-Integrated Query (LINQ) technology, the latest in .NET Framework 3.5 language capabilities. LINQ to XML provides a query experience that is similar to SQL. It allows programmers to write powerful queries.

For developers writing new code, Microsoft recommends using LINQ to XML for processing XML data. LINQ to XML is an easily-learned API that allows for powerful queries and intuitive document creation or transformation. It is a component of the .NET Language Integrated Query (LINQ), which is designed to provide a consistent query experience for objects, relational data, and XML data.

XPathNavigator Class

The XPathNavigator class offers several editing options and navigation capabilities using a cursor model. The XML documents can be contained in an XPathDocument or an XmlDocument object.

For developers modifying existing code with XPath queries or XSLT transformations, the XPathNavigator class is the best option as it provides excellent performance for read-only processing of XML.

XmlDocument Class

The XmlDocument and its related classes are based on the W3C document object model (DOM). The DOM provides full-fidelity, such as preserving white space and multiple text nodes. Nodes can be created, inserted, removed, and modified using methods and properties based on the familiar DOM model.

For developers modifying existing code that utilizes the W3C document object model (DOM), or if adhering to this standard is a requirement the XmlDocument class is the best option

Stream-Based XML Processing

The XmlWriter and XmlReader classes provide a non-cached, forward-only means of processing XML data. XmlWriter and XmlReader objects are created using the Create and Create methods. The XmlWriterSettings and XmlReaderSettings classes allow you to specify the set of features to enable on the created XmlWriter and XmlReader objects.

For more information, see Writing XML with the XmlWriter and Reading XML with the XmlReader.

See Also

Concepts

XML Processing Options

Other Resources

XML Documents and Data