XPath如何处理XML命名空间?
如果我使用
/IntuitResponse/QueryResponse/Bill/Id
Run Code Online (Sandbox Code Playgroud)
要解析下面的XML文档,我得到0个节点.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3"
time="2016-10-14T10:48:39.109-07:00">
<QueryResponse startPosition="1" maxResults="79" totalCount="79">
<Bill domain="QBO" sparse="false">
<Id>=1</Id>
</Bill>
</QueryResponse>
</IntuitResponse>
Run Code Online (Sandbox Code Playgroud)
但是,我没有在XPath中指定命名空间(即http://schema.intuit.com/finance/v3不是路径的每个标记的前缀).Id如果我没有明确告诉它,XPath怎么知道我想要哪个?我想在这种情况下(因为只有一个命名空间)XPath可以xmlns完全忽略它.但如果有多个名称空间,事情可能会变得丑陋.