|A good understanding of XML will be an added advantage to work with it.
The eXtensive Markup Language has a very important role in web applications. .Net has given enough space for XML classes in its framework. The main classes working with XML data are as follows: -
The XmlTextReader class is an implementation of XmlReader.
It provides a fast, performant parser.
It enforces the rules that XML must be well formed.
It is neither a validating nor a non-validating parser since it does not have DTD or schema information.
It can read text in blocks, or read characters from a stream.
The XmlTextReader performs the following functions:
- Enforces the rules that XML must be well-formed.
- Checks that the DTD is well-formed. However, does not use the DTD for validation, expanding entity references, or adding default attributes.
- Validating is not done against DTDs or Schemas.
- Checks the correct formation of any DOCTYPE nodes.
- Checks the correct formation of the entities. For node types of EntityReference, a single empty EntityReference node is returned. An empty EntityReference node is one in which its Value property is a string. Empty. This is because there is no DTD or schema to expand the entity reference. The XmlTextReader does ensure that the whole DTD is well-formed, including the EntityReference nodes.
- Provides a performant XML parser, because the XmlTextReader does not havethe overhead involved with validation checking.
Represents a writer that provides a fast, non-cached, forward the only way of generating streams or files containing XML data that conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations.
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 that enables the navigation and editing of this document.
This class Allows structured data to be stored, retrieved, and manipulated through a relational DataSet.
The XmlNodeReader has the ability to read an XML DOM sub tree. This class does not support DTD or schema validation.
This class enables to navigate an XML document represented by XmlDocument class.
XML with Dataset
In the previous chapters DataSet was used with SqlServer. A DataSet can also be used with XML data. The following example shows how to read an XML document into a Dataset.
Reading an XML document into a DataSet
A XML file directly can be directly read from the hard drive into DataSet by using the ReadXml () method of the DataSet class. The following example demonstrates it: -
<%@ Import Namespace="System.Data" %>
Dim dstMenu As DataSet
dstMenu = New DataSet()
dstMenu.ReadXml( MapPath( "Items.xml" ))
dgrdMenu.DataSource = dstMenu