加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

XML文档中索引节点的XPath

发布时间:2020-12-16 22:45:48 所属栏目:百科 来源:网络整理
导读:我有以下文件.我正在尝试进行测试:ABCSite [0]的类别. 试过XPath $ABCCustomerHierarchy(// ata:ABCSite [0])/ test:Customer / test:CustomerID / test:Category,但是我得到了一些XPath异常. 请问有人告诉我正确的XPath吗? test:ABCCustomerHierarchy
我有以下文件.我正在尝试进行测试:ABCSite [0]的类别.
试过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']

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读