我有以下文件.我正在尝试进行测试:ABCSite [0]的类别. 试过XPath $ABCCustomerHierarchy(// ata:ABCSite [0])/ test:Customer / test:CustomerID / test:Category,但是我得到了一些XPath异常. 请问有人告诉我正
试过XPath $ABCCustomerHierarchy(// ata:ABCSite [0])/ test:Customer / test:CustomerID / test:Category,但是我得到了一些XPath异常.
请问有人告诉我正确的XPath吗?
<test:ABCCustomerHierarchy xmlns:test="http://wwwin.test.com/testschema"> <test:ABCSite> <test:Customer> <test:CustomerID> <test:ID>110984181</test:ID> <test:Category>ABC_Customer</test:Category> </test:CustomerID> </test:Customer> <test:CustomerReferences> <test:CustomerID> <test:ID>17808</test:ID> <test:Category>KLM_CUSTOMER</test:Category> </test:CustomerID> <test:CustomerID> <test:ID>17808</test:ID> <test:Category>XYZ_Customer</test:Category> </test:CustomerID> <test:CustomerID> <test:ID>17808</test:ID> <test:Category>PQR_CUSTOMER</test:Category> </test:CustomerID> </test:CustomerReferences> </test:ABCSite> <test:ABCSite> <test:Customer> <test:CustomerID> <test:ID>17808</test:ID> <test:Category>XYZ_Customer</test:Category> </test:CustomerID> </test:Customer> <test:CustomerReferences> <test:CustomerID> <test:ID>17808</test:ID> <test:Category>PQR_CUSTOMER</test:Category> </test:CustomerID> </test:CustomerReferences> </test:ABCSite> </test:ABCCustomerHierarchy>您应该始终指定命名空间(测试您的示例)
另一点是数组从1开始而不是零
如果要获取该节点的值,请使用text():
//test:ABCSite[1])/test:Customer/test:CustomerID/test:Category/text()
要与精确值匹配使用:
//test:ABCSite[1])/test:Customer/test:CustomerID/test:Category[text()='ABC_Customer']