Solved

XPath

Posted on 2013-11-01
2
313 Views
Last Modified: 2013-11-03
Hello, might someone explain to me what this paragraph is saying about "/";
Which is the right of / ?  For example: 1/2, I consider 2 to be to the right of /.  Is this the way it is used in the explanation below?:
http://en.wikipedia.org/wiki/XPath_2.0
Path expressions[edit]

The location paths of XPath 1.0 are referred to in XPath 2.0 as path expressions. Informally, a path expression is a sequence of steps separated by the "/" operator, for example a/b/c (which is short for child::a/child::b/child::c). More formally, however, "/" is simply a binary operator that applies the expression on its right-hand side to each item in turn selected by the expression on the left hand side. So in this example, the expression a selects all the element children of the context node that are named <a>; the expression child::b is then applied to each of these nodes, selecting all the <b> children of the <a> elements; and the expression child::c is then applied to each node in this sequence, which selects all the <c> children of these <b> elements.
0
Comment
Question by:chima
2 Comments
 
LVL 51

Accepted Solution

by:
Mark Wills earned 500 total points
ID: 39618671
Not sure I understand your question...

XPATH basically provides a "tree" representation of an XML document... Meaning we can interrogate an XML document via referencing the Nodes directly.

 Which means that path expressions represents the locations within the tree. The expressions are relative and each path is separated by the "/". So think of the path as pointing to a particular node.

Lets take the example of :
<cars>

 <car>
   <make>Ferrari</make>
   <price>500000.00</price>
 </car>

 <car>
   <make>Lamborghini</make>
   <price>600000.00</price>
 </car>

 <car>
   <make>Pagani</make>
   <price>700000.00</price>
 </car>

</cars> 

Open in new window


To select (or point to) all the makes, then the Path would be :
/cars/car/make

To return the actual text of all makes,  then the Path would be :
/cars/car/make/text()

So the right hand side of the "/" has the expression of what the xpath is referring to.  Or really what it needs to do with the nodes as referenced on the left. In the first example above, it is the node "make" in the second example the expression is asking for the actual values (the text() expression).

Take the example of :
/cars/car[price>500000]/make/text()

that's got an expression car[price>500000] that is used to select car nodes with a price > 500000 and then goes on to get the text value of the "make"

When going through these types of examples, always best to start with a sample XML document.

See the W3 standards : http://www.w3.org/TR/xpath20/#id-path-expressions

Or use the tutorials : http://www.w3schools.com/xpath/default.asp

Using the above rather than wiki should / might make it easier for you.
0
 

Author Closing Comment

by:chima
ID: 39620436
Good explanation.  I started to read the "specification" and then thought this is "useless."  I needed some examples or tutorial.  I found the 3WC tutorial.
I got another question asked.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now