Reputation: 95
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]")
Upvotes: 1
Views: 1327
Reputation: 89325
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.
Upvotes: 2