Tip

.NET tools for working with XML

A lot of people associate the .NET framework with XML, and for good reason. .NET uses XML behind the scenes to implement many of its development tools, such as SOAP and Web services. Beyond that, however, .NET provides a powerful set of classes for working with XML directly. Whatever you need to do with XML—sequential or random access, validation, transforms, or output—the .NET Framework provides you with tools that are not only powerful but easy to use.

This article from

    Requires Free Membership to View

InformIT provides an overview of the most important of these classes. All of .NET's XML classes are in the System.XML namespace, and support the following standards (listed with their WWW namespaces):

XmlTextReader
The XmlTextReader class provides non-cached, forward-only access to a stream of XML data. It is designed specifically for fast access to XML data while placing minimal demands on the system's resources. Functionally, XmlTextReader is similar to the Simple API for XML (SAX), another technique for reading XML that is popular with non-.NET programmers.

XmlValidatingReader
The XmlValidatingReader class, as its name implies, provides data validation capabilities. Specifically, it can validate XML data against a document type definition (DTD), an XML schema definition language (XSD) schema, or an XML Data Reduced (XDR) schema. This class does not work alone; it must be used in conjunction with an instance of XmlTextReader that is passed to the constructor. Thus, this class gives you the forward-only capabilities of XmlTextReader with validation added. XmlValidatingReader also adds support for default attributes and the ability to resolve external references. Validation of XML data is an inherently complex and slow process.

XmlDocument
The XmlDocument class implements the W3C Document Object Model (DOM) core levels 1 and 2. This class provides random, cached access to the XML data. In other words, the data is held in memory and your program can move forward and backward as needed. Actually, "forward" and "backward" are not really accurate, because the DOM represents XML data as a tree of nodes, so what you are really doing is "walking the tree." The XmlDocument class also permits you to modify the document's data and structure.

Other Classes in System.XML
We've looked at three of the most important XML-related .Net classes, but there are many more that cannot be covered here. For example, the XmlTextWriter class lets you create XML output that conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations. And the XslTransform class transforms XML data using an XSLT stylesheet.

XML is becoming increasingly important as a data storage and transfer standard in many areas of information technology. With the tools provided by the .NET Framework, you should be able to handle essentially any XML-related programming task.


Click over to InformIT to read the original article which includes more in-depth descriptions of the above classes as well as examples.


This was first published in May 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.