获取 xmllint xpath soap
Get xmllint xpath soap
我需要解析 xml:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body> <m:runResponse xmlns:m="http://www">
<m:return xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">true;231;470;159;194;1439;476;637;99842;1164</m:return>
</m:runResponse></soap:Body>
</soap:Envelope>
并且需要
true;231;470;159;194;1439;476;637;99842;1164
我愿意:
xmllint --xpath "/soap:Envelope/soap:Body/m:runResponse/m:return" out.xml
并得到结果:
XPath error : Undefined namespace prefix
xmlXPathEval: evaluation failed
XPath evaluation failure
我该如何解析它?
使用xmllint
:
xmllint --xpath "//*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='runResponse']/*[local-name()='return']/text()" file.xml
但我更喜欢 xmlstarlet
,我觉得它更容易一些:
xmlstarlet sel -N soap="http://www.w3.org/2003/05/soap-envelope" -N m="http://www" -t -v '//soap:Envelope/soap:Body/m:runResponse/m:return' file.xml
我需要解析 xml:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body> <m:runResponse xmlns:m="http://www">
<m:return xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">true;231;470;159;194;1439;476;637;99842;1164</m:return>
</m:runResponse></soap:Body>
</soap:Envelope>
并且需要
true;231;470;159;194;1439;476;637;99842;1164
我愿意:
xmllint --xpath "/soap:Envelope/soap:Body/m:runResponse/m:return" out.xml
并得到结果:
XPath error : Undefined namespace prefix
xmlXPathEval: evaluation failed
XPath evaluation failure
我该如何解析它?
使用xmllint
:
xmllint --xpath "//*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='runResponse']/*[local-name()='return']/text()" file.xml
但我更喜欢 xmlstarlet
,我觉得它更容易一些:
xmlstarlet sel -N soap="http://www.w3.org/2003/05/soap-envelope" -N m="http://www" -t -v '//soap:Envelope/soap:Body/m:runResponse/m:return' file.xml