1

I want to find the <issue> where id = 6. How do I do it? I tried the following, but it didn't work:

<issues>
<issue>
  <id>7</id>
  <project id="1" name="testProject"/>      
  <author id="1" name="testAuthor"/>     
  <subject>subject</subject>
  <start_date>2015-08-24</start_date>      
</issue>
<issue>
  <id>6</id>
  <project id="2" name="testProject2"/>      
  <author id="2" name="testAuthor2"/>     
  <subject>subject2</subject>
  <start_date>2015-08-24</start_date>    
</issue>
</issues>

My XPath expression attempts are:

doc.xpath("//id[contains(text(), '6']") 

and

doc.xpath("//issue[@id=6]") 
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
yak_ilnur
  • 95
  • 1
  • 10

1 Answers1

2

You can simply use the following XPath expression to get the issue element having a child element where id equals 6:

//issue[id=6]

id is a child element, not an attribute so you don't use @id for this task.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
har07
  • 88,338
  • 12
  • 84
  • 137
  • @yak_ilnur you're welcome. Don't forget to [accept](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) the answer since it actually *answered* your question – har07 Oct 10 '15 at 07:16