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 Help on an XPath Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Help on an XPath Expression" Watch "Help on an XPath Expression" New topic
Author

Help on an XPath Expression

Rob Bass
Ranch Hand

Joined: Aug 28, 2001
Posts: 67
This is my XML file:
<FILEENTRY Format="xml" Last_Modified="2001-12-19T09:43:24" filename="booktest.xml" lock="false" open="false">
<KEYWORDS value="test"/>
<KEYWORDS value="test2"/>
</FILEENTRY>
<FILEENTRY Format="xml" Last_Modified="2000-01-15T12:00:00" filename="Test1.xml" lock="false" open="false" >
<KEYWORDS key='doug' value="hope"/>
<KEYWORDS value="test"/>
<KEYWORDS value="m1a1"/>
</FILEENTRY>

What XPath expression would I use to retrieve the FILEENTRY Node, that matches the key value pair? I have used this but it is ignoring the second part:
String xPathExp = "//FILEENTRY/KEYWORDS[@value='hope'] | //FILEENTRY/KEYWORDS[@key='doug1']";
although the first expression is true, the second is false, but it still returns the node that has the filename=Test1.xml, why is not using the and operator?
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
If you want to check for both conditions, you should use "and"
"... FILEENTRY[./KEYWORDS/@value='hope' and ./KEYWORDS/@key='doug']"


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Rob Bass
Ranch Hand

Joined: Aug 28, 2001
Posts: 67
I looked at an XPath tutorial and did not see where u could use AND.
David Peterson
author
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
Originally posted by Rob Bass:
I looked at an XPath tutorial and did not see where u could use AND.

Oh well if your tutorial doesn't say where you can use AND then the spec must be wrong and the above poster must be wrong and this can't possibly work:
...KEYWORDS[@value='hope' and @key='doug']
David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help on an XPath Expression