HOME

XPath Tutorial
XPath HOME
XPath Intro
XPath Syntax
XPath Locations
XPath Expressions
XPath Functions
XPath Examples
Download XMLSpy here
Please visit our sponsors !

XPath Introduction

Previous Next

XPath is a set of syntax rules for defining parts of an XML document.


What is XPath?

  • XPath is a syntax for defining parts of an XML document
  • XPath uses paths to define XML elements
  • XPath defines a library of standard functions
  • XPath is a major element in XSLT
  • XPath is not written in XML
  • XPath is a W3C Standard

Like Traditional File Paths

XPath uses path expressions to identify nodes in an XML document. These path expressions looks very much like the expressions you see when you work with a computer file system:

w3schools/xpath/default.asp


XPath Example

Look at this simple XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
  <cd country="USA">
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <price>10.90</price>
  </cd>
  <cd country="UK">
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <price>9.90</price>
  </cd>
  <cd country="USA">
    <title>Greatest Hits</title> 
    <artist>Dolly Parton</artist> 
    <price>9.90</price> 
  </cd>
</catalog>

The XPath expression below selects the ROOT element catalog:

/catalog

The XPath expression below selects all the cd elements of the catalog element:

/catalog/cd

The XPath expression below selects all the price elements of all the cd elements of the catalog element:

/catalog/cd/price

Note: If the path starts with a slash ( / ) it represents an absolute path to an element!


XPath Defines a Library of Standard Functions

XPath defines a library of standard functions for working with strings, numbers and Boolean expressions.

The XPath expression below selects all the cd elements that have a price element with a value larger than 10.80:

/catalog/cd[price>10.80]



XPath is Used in XSLT

XPath is a major element of the XSLT standard. Without XPath knowledge you will not be able to create XSLT documents.

You can read more about XSLT in our XSLT tutorial.


XPath is a W3C Standard

XPath was released as a W3C Recommendation 16. November 1999 as a language for addressing parts of an XML document.

XPath was designed to be used by XSLT, XPointer and other XML parsing software.

You can read more about XML and XSL standards in our W3C tutorial.


Previous Next

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISProtect
Password Protect
Your Web Pages



Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search