This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes XPath for atrib. name and value of node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath for atrib. name and value of node" Watch "XPath for atrib. name and value of node" New topic
Author

XPath for atrib. name and value of node

Pavol Sestak
Greenhorn

Joined: Nov 18, 2008
Posts: 2
Hello
i have specific problem with select from xml data via xpath. Here is the chunk of my xml file:
<zwk_export>
<record>
<field name="DEPOT_NR">1</field>
<field name="VALUE">463.18</field>
<field name="ART">1</field>
</record>
<record>
<field name="DEPOT_NR">1</field>
<field name="VALUE">5350.00</field>
<field name="ART">2</field>
</record>
...
<zwk_export>

Now i need to select all nodes "record" that has child "field" (note: all children are named "field") with attribute named "name" and value of that attrib. "ART" and value of the child node must be "1".
I tried these :
record[field/@name='ART' and (field/@name='ART') = '1']
record[field/@name = 'ART' and field/. = '1']

but these selected all nodes "field" that has child node "field" with attribute "name" and value of that attribute "ART" and has child "field" with value "1" (e.g. with child "DEPOT_NR" with value "1")but it is not able to select only "record" with such child:
<field name="ART">1</field>

The main problem is it mixes child <field name="ART">1</field>
and <field name="DEPOT_NR">1</field> but i do need identify positively "records" only with child <field name="ART">1</field>.

Can anyone help me?
Pavol Sestak
Greenhorn

Joined: Nov 18, 2008
Posts: 2
If someone is interested here is the solution:
record[field[@name='ART'][.='1']]
 
wood burning stoves
 
subject: XPath for atrib. name and value of node