Reputation: 25
I need XPath syntax (for use in simplexml) for searching the contents of the LayoutPosNo
element that matches exactly, say, the number 1001 and returning the text in the sibling Descrip
element. The LayoutPosNo
's are all unique, so I only need the first match.
Here is the structure of the XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<LayoutPosNo>10</LayoutPosNo>
<Descrip>This is the red room</Descrip>
</record>
<record>
<LayoutPosNo>993</LayoutPosNo>
<Descrip>This is the yellow room</Descrip>
</record>
<record>
<LayoutPosNo>1001</LayoutPosNo>
<Descrip>This is the purple room</Descrip>
</record>
</data-set>
Upvotes: 1
Views: 1008
Reputation: 111726
The following XPath
/data-set/record[LayoutPosNo = 1001]/Descrip/text()
will select
This is the purple room
as requested.
Upvotes: 1