tags:

views:

82

answers:

2

My XML:

<root>
  <cars>
    <makes>
      <honda year="1995">
        <model />
        <!-- ... -->
      </honda>
      <honda year="2000">
        <!-- ... -->
      </honda>
    </makes>
  </cars>
</root>

I need a XPath that will get me all models for <honda> with year 1995.

so:

/root/cars/makes/honda

But how to reference an attribute?

+4  A: 

Try /root/cars/makes/honda/@year

UPDATE: reading your question again:

   /root/cars/makes/honda[@year = '1995']

Bottom line is: use @ character to reference xml attributes.

Rubens Farias
+4  A: 

"I need a XPath that will get me all models for <honda> with year 1995."

That would be:

/root/cars/makes/honda[@year = '1995']/model
Tomalak