Solved

XPath

Posted on 2013-11-01
2
312 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

746 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

13 Experts available now in Live!

Get 1:1 Help Now