File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Xpath - find node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Xpath - find node" Watch "Xpath - find node" New topic
Author

Xpath - find node

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Hello,

Let´s say I want to find the page node with the value 'B2' using Xpath. How can we find the page node if we know the parent node value in a single expression. I have tried the following expression but it doesn´t seem to work:

content/pageGroup/page[.='B1']/pageGroup/page[.='B2']

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

(Note: I edited your post so that the document was indented in such a way that you can see its structure. When you posted it, the indentation was apparently random. This doesn't help in analyzing it.)

Anyway, now that you can see how the XML is organized, you can see that the <page> element whose string value is B1 doesn't have any <pageGroup> children. So when you ask for its <pageGroup> children, that's where you go wrong. Instead you need to go back to its parent element before looking for <pageGroup> children.
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Paul Clapham wrote:(Note: I edited your post so that the document was indented in such a way that you can see its structure. When you posted it, the indentation was apparently random. This doesn't help in analyzing it.)

Anyway, now that you can see how the XML is organized, you can see that the <page> element whose string value is B1 doesn't have any <pageGroup> children. So when you ask for its <pageGroup> children, that's where you go wrong. Instead you need to go back to its parent element before looking for <pageGroup> children.


Arrh... yes of course. I didn´t thought about that... Thank you for your quick reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Xpath - find node
 
Similar Threads
Selecting text without a node with XPath
XPath expression constrained by a predicate doesn't work (//element[@attribute="value"])
operator precedence
have node object, need to view it's xml?
XPath: Check if a node actually exists