Given this XML:
<log>
<xplmsg logdate="31-03-11 23:30:55" >
<schema>
<infopairs>
<info name="device" value="Blah Humidity" ></info>
<info name="type" value="humidity" ></info>
</infopairs>
</schema>
</xplmsg>
</l开发者_运维技巧og>
What xPath would return:
<xplmsg logdate="31-03-11 23:30:55" >
<schema>
<infopairs>
<info name="device" value="Blah Humidity" ></info>
<info name="type" value="humidity" ></info>
</infopairs>
</schema>
</xplmsg>
Including logdate="31-03-11 23:30:55"
I think you want
/log/xplmsg[@logdate = '31-03-11 23:30:55']
While @Alejandro's answer is correct, there is even simpler XPath expression that selects exactly the wanted element:
/*/xplmsg
or even:
/*/*
This is due to the fact that in the provided XML document the top element has a single child element -- and in this case it is not necessary to specify specific attribute name/value or even the name of the element that we want to be selected.
In case you want all of the nodes of the xplmsg
subtree to be selected, then use this XPath expression:
/*/xplmsg//@* | /*/xplmsg//node()
精彩评论