Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help on an XPath Expression

 
Rob Bass
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?
 
Mapraputa Is
Leverager of our synergies
Sheriff
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.
 
David Peterson
author
Ranch Hand
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic