Solved

XPath

Posted on 2013-11-01
2
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

730 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