Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ned help with "XPath"

 
Vivek Saxena
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help to understand the “Xpath” expression. I am reading tutorial from “Zvon” site, which is very good. Still I am little bit confuse.

I would only assume that we have a XML document with “/AAA” as the root element.

I am having hard time with “//” in an expression.
What is the meaning/difference of/between following expression?

Example # 1
//DDD/BBB
/DDD//BBB


Example # 2
//AAA/BBB
/AAA//BBB
//BBB
I think (not sure) that we will get same out put from all three expressions. Even if we get same out put but I don’t know why?



Example # 3
//AAA/BBB/CCC
/AAA/BBB//BBB



Example # 4
/AAA/BBB/CCC//
/AAA/BBB/BBB//*

If there is any tool which i can use to play around, please adivse me.
Please help me to understand above expressions. If there is any good tutorial please advise.
I would really appreciate.
Thanks
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WOW! lot of questions in that post.....let me try....
Example # 1
//DDD/BBB

For all DDD elements, select the BBB child, if any.
/DDD//BBB
For the /DDD (root) element, select all the BBB decendant elements (child, grand-child, grand-grand child BBB elements).

Example # 2
//AAA/BBB
/AAA//BBB

These are same as Example 1.
//BBB
Select all the BBB elements (irrespective of who the parent is) in the document.
I think (not sure) that we will get same out put from all three expressions. Even if we get same out put but I don�t know why?
It all depends on the input file. Its possible to get different output, depending on how your file is.
Example # 3
//AAA/BBB/CCC

For all AAA elements, select the grand child CCC element whose parent is BBB.
/AAA/BBB//BBB
Select all BBB elements whose immediate parent is BBB, whose immediate parent is AAA.
Example # 4
/AAA/BBB/CCC//

You haven't selected anything ?
/AAA/BBB/BBB//*
Select all decendants of the element "/AAA/BBB/BBB".
Its like walking down a hirearchy....say the way you find a file /jranch/usr/vsaxena/xml/cert/example1.xml on a unix machine or say C:\jranch\use\vsaxena\xml\cert\*.
If you would like, we could take each example and try it with an example file. That will definetly help. I don't know any tools other than writing a style sheet and running it on an example file.
Hope this helps.
- madhav
 
Vivek Saxena
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Madhav,
Things are now much clear. I just came to know i can play with all the examples of "Zvon" tutorial in "Xlab" on same web site.
I really appreciate it!
Thanks
 
Vivek Saxena
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just want to share. There is a very good tool called Xpath Visualiser. it helped me a lot to understand the "Xpath expression. May be it will help you.
Thanks
[ February 21, 2003: Message edited by: Vivek Saxena ]
 
Hariharan Raman
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek,
Thnaks a lot for mentioning the XPath Visualiser. It really has good amount of resources. Hope you noticed the Quizzes sections on XML, DOM and XSLT on your right which is also good to test our basics.
Thanks again..!
Hari.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic