<courses>
<course number = "1" category = "A">
<title>B</title>
</course>
</courses>
I want to pick all @number has category= "A" I try to use //@number[@category/text()='A'], but it seem no work, So how can I get it
To get @number
attribute value of <course>
node with category='A'
:
//course[@category='A']/@number
Your XML is invalid, you need quotation marks around 1
:
<course number="1" category = "A">
For attribute values, you never need text()
. Use
//@number[../@category="A"]
It means:
//@number
: select any number attribute[...]
: which satisfies the condition../
: go up to the parent (element course
or other)@category
: find a category attribute="A"
: which has the value A