DarkW1nter
DarkW1nter

Reputation: 2861

Xpath working in Notepad++ but not in .NET application

In the XML at the bottom of this post I can retrieve 'invunique' using this xpath

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

It works fine in the Notepad++ XPatherizer plugin, but when I put the same XPath into a utility class and pass in the same message it doesn't work. I've tried in both my BizTalk app and a .Net test page.

Can anyone see why?

<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>[email protected]</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>

Upvotes: 1

Views: 643

Answers (1)

har07
har07

Reputation: 89325

Your XPath didn't work for me either, even in an XPath tester. The problem is in this part :

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

You didn't ignore namespace when testing the element invno. Here is a way to fix the above XPath part :

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

Now the XPath successfully return <invunique> element : xpathtester demo

Upvotes: 2

Related Questions