我需要解析这个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>需要得到
真;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我怎么能解析它?
发布于 2018-10-02 14:15:40
使用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.xmlhttps://stackoverflow.com/questions/52609492
复制相似问题