This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help on an XPath Expression

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic