-1

How to parse xml element using attribute value. i am using Dom for parsing XML file. i am not sure for parsing xml element only having attribute value. is this possible in DOM..??

RAAAAM
  • 3,346
  • 18
  • 58
  • 107
  • possible duplicate of [Getting element using attribute](http://stackoverflow.com/questions/6093121/getting-element-using-attribute) – Jon Skeet May 23 '11 at 06:46
  • Actual guess for the question (including the duplicate): "How to find/select all elements in a XML document that have a given attribute value" ... – Andreas Dolk May 23 '11 at 07:14

1 Answers1

0

The following XPath expression will select all elements that have given attibute/attribute-value pair:

//*[@foo="bar"]

Example:

<root>
 <grand foo="bar">    <!-- selected -->
   <child foo="nobar"/>
 </grand>
 <grand foo="nobar">
   <child foo="bar"/> <!-- selected -->
 </grand>
</root>

Here's a tutorial for the Java XPath API (jaxp). It has some snippets that show how to use it.

Andreas Dolk
  • 111,016
  • 17
  • 174
  • 259