What is XPath?
XPath is a language for addressing an XML document's elements and attributes. As
an example, say you receive an XML document that contains the details of a
shipment and you want to retrieve the element/attribute values from the XML
document. You don't just want to list the values of all the nodes, but also
want to output the values of specifi c elements or attributes. In such a case,
you would use XPath to retrieve the values of those elements and attributes.
XPath constructs a hierarchical structure of an XML document, a tree of nodes,
which is the XPath data model. The XPath data model consists of seven node
types. The different types of nodes in the XPath data model are discussed in
the following table:
Node Type |
Description |
Root Node |
The root node is the root of the DOM tree. The document element (the root
element) is a child of the root node. The root node also has the processing
instructions and comments as child nodes. |
Element Node |
This represents an element in an XML document. The character data, elements,
processing instructions, and comments within an element are the child nodes of
the element node. |
Attribute Node |
This represents an attribute other than the xmlns-prefi xed attribute, which
declares a namespace. |
Text Node |
The character data within an element is a text node. A text node has at least
one character of data. A whitespace is also considered as a character of data.
By default, the ignorable whitespace after the end of an element and before the
start of the following element is also a text node. The ignorable whitespace
can be excluded from the DOM tree built by parsing an XML document. This can be
done by setting the whitespace-preserving mode to false with the
setPreserveWhitespace(boolean flag) method. |
Comment Node |
This represents a comment in an XML document, except the comments within the
DOCTYPE declaration. |
Processing Instruction Node |
This represents a processing instruction in an XML document except the
processing instruction within the DOCTYPE declaration. The XML declaration is
not considered as a processing instruction node. |
Namespace Node |
This represents a namespace mapping, which consists of a xmlns:-prefi xed
attribute such as xmlns:xsd="http://www. w3.org/2001/XMLSchema". A namespace
node consists of a namespace prefi x (xsd in the example) and a namespace URI
(http://www.w3.org/2001/XMLSchema in the example). |
Specifi c nodes including element, attribute, and text nodes may be accessed
with XPath. XPath supports nodes in a namespace. Nodes in XPath are selected
with an XPath expression. An expression is evaluated to yield an object of one
of the following four types: node set, Boolean, number, or string.
An example of a location step is:
child::journal[position()=2]
In the example, the child axis contains the child nodes of the context node.
Node test is the journal node set, and predicate is the second node in the
journal node set. An absolute location path is defi ned with respect to the
root node, and starts with "/". The difference between a relative location path
and an absolute location path is that a relative location path starts with a
location step, and an absolute location path starts with "/".
Also read
What is XQuery language?
Explain the syntax rule of XQuery language.
XQuery expression contains two parts: the Prolog and the Body. Explain them
Explain PATH expression in XQuery with an example.
Answer - XML data binding refers to the process of representing
the information in an XML document as an object in computer
memory...............
Answer - You need to first create a table in oracle that
matches with the fields of the XML data...............
Answer - SQL Server 2000 provides the facility to retrieve data
in the form of XML with the help of the FOR XML clause appended to the end of a
SELECT statement. ..............
|