Wednesday, 1 December 2010

XPath

What is Xpath and what does it do? Evaluate the strengths and weaknesses of this concept, with examples.
# XPath is a language for discovering information in an XML document and also illustrating a way to locate and process items in XML by using an addressing syntax based on a path through the documents logical structure or hierarchy. The data in an XML document can be retrieved with JAXP (Java API for XML Processing) DOM and SAX APIs but addressing with Xpath it has a benefit like a single node may be selected directly without iterating over a node set. As with other two, node lists have to be iterated over to access a particular node. It uses path expression for navigating in XML documents. It is a language, used by and stated as part of the Extensible Stylesheet Language Transformations (XSLT) and by Xpointer (SML Pointer Language).
Xpath is a language for selecting nodes from an XML document. It also provides basic facilities to compute value from the XML Document such as strings, number and boolean values.
There are seven node types in XPath data model:
·         Root node
·         Element Node
·         Attribute node
·         Text Node
·         Comment Node
·         Processing instruction node
·         Namespace node
Some of XPath strengths are like its simple expression can solve many queries and computations, it’s unfussy to use. Whereas, there are some weakness as well such as its hard nearly impossible to solve complex queries or computations and it can be unfeasible for huge documents because it is slow for large documents and uses a lot of resources. A simple example for XPath is as follows:
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<bookstore>[document node]<
book><title lang=”en”>[attribute]P.S. I love you</title>[element]<
author>Kshitij Munankami</author>
<year>2010</year>
<price>100</price>
</book>
</bookstore>

No comments:

Post a Comment