• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help on an XPath Expression

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to check for both conditions, you should use "and"
"... FILEENTRY[./KEYWORDS/@value='hope' and ./KEYWORDS/@key='doug']"
 
Rob Bass
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I looked at an XPath tutorial and did not see where u could use AND.
 
author
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic