Accessing and Manipulating XML Data in Microsoft .NET Framework
by Team uCertifyuCertify.com
Wednesday, 23rd August 2006
The XML Path (XPath) Language
XML Path or XPath language described by the W3C Standard is a query language for finding information in an XML document. XPath uses path expressions to select a set of nodes and to navigate through elements and attributes in an XML document. XPath also contains built-in standard functions to manipulate string, numeric, and boolean values, and to manipulate sequences and nodes. XPath also defines different types of nodes such as element, attribute, text, namespace, processing instruction, and comment of an XML document and the relationship between the nodes in a document.
The XPathNavigator class derived from the System.Xml.XPath namespace performs XPath queries on any data source such as an XML document, a database or a DataSet. An XPathNavigator object for an XML document can be created by using the CreateNavigator method of the XmlNode and XPathDocument classes that implement the IXPathNavigable interface. The CreateNavigator method returns an XPathNavigator object that can be used to perform XPath queries. The XPathNavigator object reads data from an XML document that enables forward and backward navigation within the nodes therefore providing random access to nodes. The XPathNavigator objects formed by XmlDocument objects can be edited whereas those formed by XPathDocument objects are read-only.
The following are the steps to perform XPath queries that uses some of the methods of the XPathNavigator class:
1.A set of nodes should be selected first before performing XPath queries.
2.The Select method of the XPathNavigator object is used to select the set of nodes that returns an object of the XPathNodeIterator class.After obtaining the XPathNodeIterator object, it is then used to iterate through the selected nodes that can easily be navigable within them.
3.The XPathNavigator class also provides some additional methods besides the Select method for optimal performance such as SelectChildren, SelectAncestors, SelectDescendants, and IsDescendant methods. These methods except the IsDescendant method return an XPathNodeIterator object. The state or position of the XPathNavigator object does not get affected when these methods are called.
4.After selecting a set of nodes, the nodes can be navigated randomly by using the XPathNavigator object that provides various methods for navigation. The following describes the methods that navigate a set of nodes:
- MoveTo() Moves the XPathNavigator object to another node in the current position and returns a Boolean value indicating its movement.
- MoveToNext() Moves the XPathNavigator object to the next sibling of the current node.
- MoveToPrevious() Moves the XPathNavigator object to the previous sibling of the current node.
- MoveToFirst() Moves the XPathNavigator object to the first sibling of the current node.
- MoveToFirstChild() Moves the XPathNavigator object to the first child of the current node. The current node must be the root node or has child nodes.
- MoveToParent() Moves the XPathNavigator object to the parent node of the current node. The current node must not be the root node.
- MoveToRoot() Moves the XPathNavigator object to the root node.
- MoveToId() Moves the XPathNavigator object to the node that contains an ID attribute. The ID of the node must be specified.
5.Additionally, the Evaluate method can be used to evaluate XPath expressions that returns required results, and also performs various calculations.
As the XML Document Object Model creates and manipulates an XML document, the XML Schema Object Model creates an XML schema. The following sub-heading is a description of the XML Schema Object Model or XML SOM.
Options:
Printer Friendly
Email Friend
uCertify was formed in 1996 with an aim to offer high quality educational training software and services in the field of information technology to its customers. uCertify provides exam preparation solutions for the certification exams of Microsoft, CIW, CompTIA, Oracle, Sun and other leading IT vendors. To know more about uCertify, please visit http://www.ucertify.com/
