问题
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>
回答1:
The following XPath
/data-set/record[LayoutPosNo = 1001]/Descrip/text()
will select
This is the purple room
as requested.
来源:https://stackoverflow.com/questions/31117609/select-node-based-on-siblings-value