Home arrow XML arrow Introduction to XPath

Introduction to XPath

According to the W3C, XPath is a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer. In this article we will learn about XPath, XPath expressions and how to use XPath in .NET and Java.

Author Info:
By: Mamun Zaman
Rating: 5 stars5 stars5 stars5 stars5 stars / 12
August 15, 2007
  1. · Introduction to XPath
  2. · Path Expression Syntax
  3. · Getting Elements
  4. · Using XPath

print this article

Introduction to XPath
(Page 1 of 4 )

XPath, XML Path Language, is an expression language for addressing portions of an XML document or navigating within an XML document. We can also get values of elements and attributes using XPath. XPath is really helpful for parsing XML- based configuration or properties files. XPath is a major element in the XSLT standard.

XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like URL and traditional file system paths. XPath also supports several functions for string manipulation, comparison and others.

First we will learn about these path expressions. XML documents are treated as trees of nodes and the root of the tree is called the document node or root node. There are about seven different kinds of nodes. They are element, attribute, text, namespace, processing-instruction, comment, and root nodes. Usually the most used nodes are element, attribute and text. Here is an XML sample.

<title id='1'>XPath Tutorial</title>
<author>Mamun Zaman</author>
<title id='2'>AJAX Tutorial</title>

In this XML sample, the root node is <bookstore>. We have two <book> elements; these are siblings. The <title> node is a child of the <book> element. Similarly, the <book> node is a parent of <title>, <author>, <year> and <price>. The <book> and <bookstore> nodes are ancestors of the <price> node. Similarly, the <book>, <title>, <author>, <year> and <price> nodes are descendants of <bookstore>, the root node. The id is an attribute node. The year value 2007 is a text node.

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials