XPath

XPATH Examples

XPATH Examples

XPATH Subjective Questions And Answers

More interview questions and answers

What is XPath?

We use Xpath language to find out the information in an XML document. Using XPath we can define the parts of an XML document.
XPath
is an main element in XSLT. Using XPath in an XML document we can perform navigation through elements and attributes.XPath has W3C Recommendation since 16 Nov 1999.

What type of standard functions are in XPath?

We can say that XPath has more than 101 build-in functions.XPath given those build-in function that are used for boolean values, string values, numeric values, date and time comparison, sequence manipulation etc.

How you define nodes in XPath?

 XPath provide us seven kinds of nodes.These are:
1.element
2.text
3.processing-instruction
4.comment
5.namespace
6.attribute
7.document node(root node).
 In XML documents nodes are structured as tree.And the root of the tree is called as document node(root node) in an XML document.


 I have given example which show you how to manage nodes in XML.

<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<bookstore>
<book>
  <title lang=\"en\">Parallel Algorithm</title>
  <author>Rashmi Sharma</author>
  <year>2008</year>
  <price>150.00</price>
</book>
</bookstore>

Now, I explain you above example interms of node.

<bookstore>  (document node or root node)
<author>Rashmi Sharma</author>  (element node)
lang=\"en\"  (attribute node)

What is Atomic values?

Nodes that has no parent node or child node are called as Atomic values.Than we can say that items are an example of Atomic values.
Example:
Rashmi Sharma
\"en\"
2008
150.00

How you define relationship among nodes?

 I have told you types of nodes.
Example:
<book>
  <title>Parallel Algorithm</title>
  <author>Rashmi Sharma</author>
  <year>2008</year>
  <price>150.00</price>
</book>


Parent : Only one parent node has possible with each element and attribute.
 In above example we can say that book element is the parent of  title, author, year, and price.

Children : An element node may have zero, one or more children.
 In above example book element has children title, author, year, and price elements.

Siblings : We called siblings those element who has same parent.
 In above example we can say that title, author, year, and price elements are siblings.

Ancestors : We can say that ancestors are node\'s parent, parent\'s parent, etc.
 In above example the ancestors of the author element are the book element and the bookstore element.Ancestors of title, author, year and price elements are same.

Descendants : We can say that ancestors are node\'s children, children\'s children, etc.
 In above example. descendants of the book element are title, author, year, and price elements.

How you define XPath Axes?

Using Axes we can set relation of current node with another node. 
Example:
ancestor : Use to get all ancestor (parent, grandparent etc) of current node.
ancestor-or-self : Use to get all ancestors (parent, grandparent, etc.) of the current node and also the current node.
attribute : Use to get all attributes of the current node.
child :    Use to get all children of the current node.
descendant : Use to get all descendants (children, grandchildren, etc.) of the current node.
namespace : Use to get all namespace nodes of the current node.
preceding : Use to get everything in the document that is comes before the start tag of the current node.
preceding-sibling : Use to get all siblings before the current node.

XPATH Subjective Questions And Answers