Writing XML




Your choice for writing is much simpler, and you want to explore the methods of the System.Xml
.XmlWriter for your XML output needs. The XmlWriter class is the core class that enables you to
create XML streams and write data to well-formed XML documents. XmlWriter is used to perform tasks
such as writing multiple documents into one output stream, writing valid names and tokens into the
stream, encoding binary data and writing text output, managing output, and flushing and closing the
output stream.

XPath Support

The XPath is used in an XML document to access a node or a set of nodes. After you create an XML
document, you might need to access a value from a certain node, and you can accomplish this using

XPath. In addition, XPath enables you to create expressions that can manipulate strings, numbers, and
Boolean values. XPath treats an XML document as a tree containing different types of nodes, which
include elements, attributes, and text. You can create XPath expressions that identify these nodes in an
XML document based on their type, name, and value. In addition, an XPath expression can identify the
relationship between the nodes in a document. The XPath implementation recognizes several node
types in an XML document, such as Root, Element, Attribute, Namespace, Text, ProcessingInstruction,
Comment, SignificantWhitespace, Whitespace, and All. The XPath functionality in the .NET Framework
is encapsulated in the System.Xml.XPath namespace. Table 3-2 describes the classes and interfaces of
the System.Xml.XPath namespace that not only enable you to perform an XPath query on an XML
document, but also update the XML document.

Table 3-2. Classes and Interfaces of the System.Xml.XPath Namespace

Classes and Interfaces Description

XPathDocument This class provides a read-only cache for a fast and highly

optimized processing of XML documents using XSLT.

XPathException This class represents the exception that is thrown when an

error occurs during the processing of an XPath expression.

XPathExpression This class encapsulates a compiled XPath expression. An

XPathExpression object is returned when you call the
Compile method. The Select, Evaluate, and Matches methods
use this class.