在这篇文章底部的XML中,我可以使用此xpath检索“ invunique”

/*[local-name()='nws_fetch_caseResponse']/*[local-name()='nws_fetch_caseResult']/*[local-name()='nwsret']/*[local-name()='Result'][invno='234567']/*[local-name()='invunique']


在Notepad ++ XPatherizer插件中,它可以正常工作,但是当我将相同的XPath放入实用程序类中并传递相同的消息时,它将不起作用。我在BizTalk应用程序和.Net测试页中都尝试过。

谁能看到原因?

<nws_fetch_caseResponse xmlns="http://bwarels.ath.cx/nexflexnws/2012/08">
  <nws_fetch_caseResult>
    <nwsret>
      <xs:schema id="nwsret" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
        <xs:element name="nwsret" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
          <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
              <xs:element name="Result">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="id" type="xs:long" minOccurs="0" />
                    <xs:element name="idtrans" type="xs:long" minOccurs="0" />
                    <xs:element name="caseunique" type="xs:string" minOccurs="0" />
                    <xs:element name="fileno" type="xs:string" minOccurs="0" />
                    <xs:element name="dtclose" type="xs:dateTime" minOccurs="0" />
                    <xs:element name="status" type="xs:string" minOccurs="0" />
                    <xs:element name="invno" type="xs:string" minOccurs="0" />
                    <xs:element name="invunique" type="xs:string" minOccurs="0" />
                    <xs:element name="paymentreference" type="xs:string" minOccurs="0" />
                    <xs:element name="addressname" type="xs:string" minOccurs="0" />
                    <xs:element name="address1" type="xs:string" minOccurs="0" />
                    <xs:element name="address2" type="xs:string" minOccurs="0" />
                    <xs:element name="address3" type="xs:string" minOccurs="0" />
                    <xs:element name="address4" type="xs:string" minOccurs="0" />
                    <xs:element name="address5" type="xs:string" minOccurs="0" />
                    <xs:element name="postcode" type="xs:string" minOccurs="0" />
                    <xs:element name="phone1" type="xs:string" minOccurs="0" />
                    <xs:element name="phone2" type="xs:string" minOccurs="0" />
                    <xs:element name="mobile" type="xs:string" minOccurs="0" />
                    <xs:element name="email1" type="xs:string" minOccurs="0" />
                    <xs:element name="invworkflow" type="xs:string" minOccurs="0" />
                    <xs:element name="invstep" type="xs:string" minOccurs="0" />
                    <xs:element name="invwsdescription" type="xs:string" minOccurs="0" />
                    <xs:element name="invdtreview" type="xs:string" minOccurs="0" />
                    <xs:element name="idowner" type="xs:string" minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:choice>
          </xs:complexType>
        </xs:element>
      </xs:schema>
      <Result>
        <id>1</id>
        <idtrans>1</idtrans>
        <caseunique>12345</caseunique>
        <fileno>4000850</fileno>
        <dtclose>2016-04-27T10:31:14.73+01:00</dtclose>
        <status>Close</status>
        <invno>234567</invno>
        <invunique>123qwert</invunique>
        <paymentreference xml:space="preserve"> </paymentreference>
        <addressname>Mr smith</addressname>
        <address1>address</address1>
        <address2>city</address2>
        <address3 />
        <address4 />
        <address5 />
        <postcode>EH32 6NG</postcode>
        <phone1 />
        <phone2 />
        <mobile />
        <email1>test@test123.com</email1>
        <invworkflow>HOLD      </invworkflow>
        <invstep>REVWCT    </invstep>
        <invwsdescription>Hold Review                                                                                                                                                                                                                                                    </invwsdescription>
        <invdtreview>18/03/2016</invdtreview>
        <idowner>SB        </idowner>
      </Result>
    </nwsret>
  </nws_fetch_caseResult>
</nws_fetch_caseResponse>

最佳答案

即使在XPath测试仪中,您的XPath也不适合我。问题出在这部分:

/*[local-name()='Result'][invno='234567']


测试元素invno时,您没有忽略命名空间。这是修复上述XPath部分的一种方法:

/*[local-name()='Result'][*[local-name()='invno' and .='234567']]


现在,XPath成功返回<invunique>元素:xpathtester demo

07-24 09:48
查看更多