错误的XPathExpression

时间:2017-05-18 09:24:38

标签: xml xpath

我有一个类似的XML文档:

    <ns0:SIM_StdNeunNulldelticket xmlns:ns0="http://DoX.BAI.BT.Schemas/001">
  <ns0:SIM_StdNeunNulldelticket PacketIds="b1cd4e60-0526-4d88-85a3-baabadc4b30f" RecIds="ae319e04-b5ce-4d67-8506-bfb09d9643f1" RecVersion="94c990aa-e98e-4f5c-8e21-9111ad4de227" SendingUserName="LAB" ExportId="23881aa6-3ba6-11e7-8d4d-901b0e8bf24b">
    <ns0:Cmsnet version="9.0">
      <ns0:delticket prim_client="1" prim_firmno="1" prim_plantno="3" prim_proddate="2017-05-18T00:00:00" prim_dtno="361487">
        <ns0:client>1</ns0:client>
        <ns0:firmno>1</ns0:firmno>
        <ns0:plantno>3</ns0:plantno>
        <ns0:proddate>2017-05-18T00:00:00</ns0:proddate>
        <ns0:dtno>361487</ns0:dtno>
        <ns0:mutation>mtProdStart</ns0:mutation>
        <ns0:batchid>4308</ns0:batchid>
      </ns0:delticket>
    </ns0:Cmsnet>
  </ns0:SIM_StdNeunNulldelticket>
  <ns0:SIM_StdNeunNulldelticket PacketIds="b1cd4e60-0526-4d88-85a3-baabadc4b30f" RecIds="1f12eabb-d2c2-4f15-948a-abed3eca5f3a" RecVersion="dfb8882a-606f-44e2-8c76-5d68274a8ce9" SendingUserName="LAB" ExportId="23881aa7-3ba6-11e7-8d4d-901b0e8bf24b">
    <ns0:Cmsnet version="9.0">
      <ns0:delticket prim_client="1" prim_firmno="1" prim_plantno="6" prim_proddate="2017-05-18T00:00:00" prim_dtno="693311">
        <ns0:client>1</ns0:client>
        <ns0:firmno>1</ns0:firmno>
        <ns0:plantno>6</ns0:plantno>
        <ns0:proddate>2017-05-18T00:00:00</ns0:proddate>
        <ns0:dtno>693311</ns0:dtno>
        <ns0:mutation>mtProdEnd</ns0:mutation>
        <ns0:batchid>4306</ns0:batchid>
      </ns0:delticket>
    </ns0:Cmsnet>
  </ns0:SIM_StdNeunNulldelticket>
</ns0:SIM_StdNeunNulldelticket>

我的XPathexression是

/*[//*[local-name() = 'delticket'] and //*[@prim_plantno='3']]

所以我想要的只是......其中plantno = 3

<ns0:SIM_StdNeunNulldelticket xmlns:ns0="http://DoX.BAI.BT.Schemas/001">
    <ns0:SIM_StdNeunNulldelticket PacketIds="b1cd4e60-0526-4d88-85a3-baabadc4b30f" RecIds="ae319e04-b5ce-4d67-8506-bfb09d9643f1" RecVersion="94c990aa-e98e-4f5c-8e21-9111ad4de227" SendingUserName="LAB" ExportId="23881aa6-3ba6-11e7-8d4d-901b0e8bf24b">
        <ns0:Cmsnet version="9.0">
            <ns0:delticket prim_client="1" prim_firmno="1" prim_plantno="3" prim_proddate="2017-05-18T00:00:00" prim_dtno="361487">
                <ns0:client>1</ns0:client>
                <ns0:firmno>1</ns0:firmno>
                <ns0:plantno>3</ns0:plantno>
                <ns0:proddate>2017-05-18T00:00:00</ns0:proddate>
                <ns0:dtno>361487</ns0:dtno>
                <ns0:mutation>mtProdStart</ns0:mutation>
                <ns0:batchid>4308</ns0:batchid>
            </ns0:delticket>
        </ns0:Cmsnet>
    </ns0:SIM_StdNeunNulldelticket>
</ns0:SIM_StdNeunNulldelticket>

但我总是得到两个(plantno 6和3)。我的问题是,我不知道应该如何编写XPathExression。

我感谢您的回复!

1 个答案:

答案 0 :(得分:0)

尝试

//*[local-name() = 'delticket' and @prim_plantno='3']

仅获取具有属性delticket

prim_plantno='3'个节点

//*[./*/*[local-name() = 'delticket' and @prim_plantno='3']]

将祖先包含在输出中