?
Solved

XPath

Posted on 2013-11-01
2
Medium Priority
?
322 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 2000 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

752 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