Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

XPath Tutorial
XPath Introduction
XPath Nodes
XPath Syntax
XPath Axes
XPath Operators
XPath Examples
XPath Summary

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


XPath Examples


Previoushome Next





XPath Example




Example: Training Log Sample XML Document

A D V E R T I S E M E N T
<?xml version='1.0'?> <DOCTYPE training system'etml.dtd'> <training>

<session date='11/10/05' type='running' heartrate='158'>
<duration units="minutes">45 </duration>
<distance units="miles">4.5 </distance>
<location>west Park </location>
<comments>little wind through out</comment>
</session>

<session date='11/11/05' type='cycling' heartrate='153'>
<duration units="hours">2.5 </duration>
<distance units="miles">37 </distance>
<location> Trace Parkway </location>
<comments>afternoon run</comment>
</session>

<session date='11/24/05' type='cycling' heartrate='153'>
<duration units="hours">1.5 </duration>
<distance units="miles">8.5 </distance>
<location> Warner Park </location>
<comments>afternoon run</comment>
</session>
</training>

Description:

The most basic of XPath patterns is the pattern that references the current node, which consists of a period sign:

.

A period will obtain the current node.when youíre traversing a document tree. Thus current node pattern is therefore a relative pattern because it makes sense only in the context of a tree of data. As a contrast to the current pattern, which is relative, consider the pattern that is used to select the root node of a document. This pattern is called as root pattern and consists of a single forward slash:

/

If you are using a single forward slash in an expression for the training log sample document, it would refer to the trainlog element because this element is the root element of the document. Because the root pattern directly references a specific location in a document (the root node), it is also considered an absolute pattern. The root pattern is extremely important to XPath because it represents the starting point of the documentís node tree.

If there are child nodes there must also be parent nodes. To access a parent node, you must use two periods:

..

As an example, if the current context is one of the distance elements then in the training log document, the .. parent pattern will reference the parent of the node, which is a session element. You can put patterns together to get more interesting results. e.g. to address a sibling node, you must first go to the parent and then references the sibling as a child. In other words, you use the parent pattern (..) followed by a forward slash (/) followed by the sibling name, like this:

../duration

This pattern assumes that the context is one of the child elements of the session element (other than duration). Assuming this context, the ../duration pattern will reference the duration element as a sibling node.

Thus far Iíve focused on referencing individual nodes. However, itís also possible to select multiple nodes. For example, you can select all of the child nodes (descendants) of a given node using the double slash pattern:

//

As an example, if the context is one of the session elements in the training log document.e.g. you can select all of its child nodes by using double slashes. This results in the duration. , distance , location , and comments elements being selected.

Another way to select multiple nodes is to use the wildcard pattern, which is an asterisk:

*

The wildcard pattern selects all of the nodes in a given context. So, if the context was a session element and you used the pattern */distance, all of the distance elements in the document would be selected. This occurs because the wildcard pattern first results in all of the sibling session elements being selected, after which the selection is limited to the child distance elements.

To summarize, following are the primary building blocks used to reference nodes in XPath:

  • Current nodeó.
  • Root nodeó/
  • Parent nodeó..
  • Child nodeóChild
  • Sibling nodeó/Sibling
  • All child nodesó//
  • All nodesó*
Referencing Subsets and Attributes

Elements are not only important pieces of information in XML documents; itís also important to be able to references attributes. Fortunately, XPath makes it quite easy to reference attributes by using the ďatĒ symbol:

@

The at symbol is used to reference attributes by preceding an attribute name:

*/distance/@units

This code selects all of the units attributes for distance elements in the training log document, assuming that the context is one of the session elements. As you can see, attributes fit right into the path notation used by XPath and are referenced in the same manner as elements, with the addition of the at (@) symbol.

One other important feature of XPath expressions is support for the selection of subsets of nodes. You select a subset by appending square brackets ([]) to the end of a pattern and then placing an expression within the brackets that defines the subset. As an example, consider the following pattern that selects all the session elements in the training log document:

*/session

Itís possible that you might want to limit the session elements to a certain type of training session, such as running. To do this, you add square brackets onto the pattern, and you create an expression that checks to see if the session type is set to running:

*/session[@type=írunningí]

This pattern results in selecting only the session elements whose type attribute is set to running. Notice that an at symbol (@) is used in front of the attribute name (type) to indicate that it is an attribute. You can also address elements by index, as the following expression demonstrates:

/session[1]

This expression selects the first session element in the document.



Be the first one to comment on this page.




  XPath Tutorial eBooks

No eBooks on XPath could be found as of now.

 
 XPath Tutorial FAQs
More Links » »
 
 XPath Tutorial Interview Questions
More Links » »
 
 XPath Tutorial Articles

No XPath Articles could be found as of now.

 
 XPath Tutorial News

No News on XPath could be found as of now.

 
 XPath Tutorial Jobs

No XPath Articles could be found as of now.


Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: XPath Examples, xpath query examples, xslt example, xslt examples, xpath example, xsl example, xsl examples, xquery examples, xquery example, xpath vb net, xpath starts with, asp net xpath, xml xslt example, java xpath example, xml xsl example, vb net examples, asp net examples, xsl fo examples, xpath case insensitive, xml xpath example, xsl fo example, xpath query example, xalan example, java xslt example, xpath tutorial, xpath sample, xml examples, xpath syntax, xpath namespace, xpath reference, xpath expressions, xpath c# , xpath namespaces, xpath xml, selectsinglenode xpath, xpath functions, xpath query, xpath attribute

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright © 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright © 2003-2017 Vyom Technosoft Pvt. Ltd., All Rights Reserved.