Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] XPath filter returns no results #2050

Closed
brad-young opened this issue Apr 24, 2020 · 12 comments · Fixed by #4083
Closed

[Bug] XPath filter returns no results #2050

brad-young opened this issue Apr 24, 2020 · 12 comments · Fixed by #4083
Labels
B-bug Bug: general classification N-help Needs: Help S-verified Status: Verified by maintainer

Comments

@brad-young
Copy link

brad-young commented Apr 24, 2020

Describe the bug
I am trying to chain together a few API calls. Step #1, get a TOKEN, Step #2, use the token in subsequent calls.

Here is the sample response from the TOKEN API call:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
  xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <LoginResponse
      xmlns="http://url/DataService/">
      <LoginResult>xxx-777-xxx-123</LoginResult>
    </LoginResponse>
  </soap:Body>
</soap:Envelope>

Then in my "next" API call, I am using the Insomnia RESPONSE functionality, by grabbing the TOKEN from the body.

Using the following XPath filter:

//*[local-name(.)='LoginResult']/text()

However, the UI in the modal window says "Returned no results".

The example does work in https://extendsclass.com/xpath-tester.html

It appears to be the xmlns value

Screenshots
attached

Desktop (please complete the following information):

  • OS: macOS 10.14.6
    Screen Shot 2020-04-24 at 12 44 44 PM
    Screen Shot 2020-04-24 at 1 07 25 PM
@nijikokun nijikokun changed the title [Bug] Short issue title [Bug] XPath filter returns no results Apr 30, 2020
@nijikokun nijikokun added the B-bug Bug: general classification label Apr 30, 2020
@gschier
Copy link
Contributor

gschier commented May 2, 2020

I think I've seen this reported before somewhere. It looks like the XPath library we're using doesn't like the xmlns="http://url/DataService/" attribute. Removing this makes the query //LoginResult work. However, the text() function also seems to be not supported, as //LoginResult/text() returns nothing.

Perhaps we should look at updating our XPath dependency or finding a more-complete one.

@brad-young
Copy link
Author

yeah, the hard part is not being able to control the TOKEN API call that adds the xmlns. And .... I don't think there's another way to do this, correct? If I want to chain together commands and grab the token value, this is really the only method.

@gschier
Copy link
Contributor

gschier commented May 4, 2020

Not quite. You could write your own fork of the Response Tag plugin or maybe make use of this one https://insomnia.rest/plugins/insomnia-plugin-response-eval

@stale
Copy link

stale bot commented May 31, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@HumanAftrAll
Copy link

HumanAftrAll commented Jun 25, 2021

I'm also facing this problem!

My XML response:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns="urn:enterprise.soap.sforce.com"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <loginResponse>
      <result>
        <metadataServerUrl>invalidurl.com/metadata</metadataServerUrl>
        <passwordExpired>false</passwordExpired>
        <sandbox>false</sandbox>
        <serverUrl>https://invalidurl.com</serverUrl>
        <sessionId>COMPLETELYINVALIDVALUE</sessionId>
        <userId>redacted</userId>
        <userInfo>
          <accessibilityMode>false</accessibilityMode>
          <currencySymbol xsi:nil="true"/>
          <orgAttachmentFileSizeLimit>5242880</orgAttachmentFileSizeLimit>
          <orgDefaultCurrencyIsoCode xsi:nil="true"/>
          <orgDefaultCurrencyLocale xsi:nil="true"/>
          <orgDisallowHtmlAttachments>false</orgDisallowHtmlAttachments>
          <orgHasPersonAccounts>false</orgHasPersonAccounts>
          <organizationId>redacted</organizationId>
          <organizationMultiCurrency>true</organizationMultiCurrency>
          <organizationName>redacted</organizationName>
          <profileId>redacted</profileId>
          <roleId>redacted</roleId>
          <sessionSecondsValid>7200</sessionSecondsValid>
          <userDefaultCurrencyIsoCode>USD</userDefaultCurrencyIsoCode>
          <userEmail>redacted</userEmail>
          <userFullName>redacted</userFullName>
          <userId>redacted</userId>
          <userLanguage>redacted</userLanguage>
          <userLocale>redacted</userLocale>
          <userName>redacted</userName>
          <userTimeZone>redacted</userTimeZone>
          <userType>Standard</userType>
          <userUiSkin>Theme3</userUiSkin>
        </userInfo>
      </result>
    </loginResponse>
  </soapenv:Body>
</soapenv:Envelope>

And I want to get the value under <sessionId> with the following XPath: /soapenv:Envelope/soapenv:Body/loginResponse/result/sessionId. Adding the extra / at the start did not work...

The same XPath works when testing it elsewhere.

@ppazos
Copy link

ppazos commented Aug 31, 2021

When I try to filter by XPath on a reponse body, to use the value in another request, I always get "no results", and then if I erase the XPath, I get "Invalid XPath query: b64::::46b" which doesn't make sense since the field is empty!

Screenshot_2021-08-30_22-35-20

This is on an insomnia just updated today!

@develohpanda
Copy link
Contributor

develohpanda commented Sep 8, 2021

There appears to be an issue with XPath if namespaces are used. For instance, if <foo><bar>baz</baz></foo> is used with the XPath of /foo/bar, then baz is returned as a result successfully, but if a namespace exists as per the example in #2050 (comment), then XPath fails to resolve it.

It appears that the XPath library we use requires the namespaces to be sent in code. 🤔 These seem to be the same findings as the previous comments where namespace attributes cause issues.

@ppazos, is the XPath query you are using by chance, operating on a response that contains namespaces? The error you found where a result is shown when the filter is empty is a valid edge case for sure - I have raised a PR to fix that: #4012.

@ppazos
Copy link

ppazos commented Sep 8, 2021

@develohpanda the xml I'm querying has ns declared in the root element:

<composition
  xmlns="http://schemas.openehr.org/v1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="COMPOSITION" archetype_node_id="openEHR-EHR-COMPOSITION.test_all_datatypes.v1">

This uses the default ns http://schemas.openehr.org/v1, so the element names don't include any ns information. For instance if you have xmlns:xxx="http://schemas.openehr.org/v1", then all tags will be xxx:tag

This is the full XML:

<composition
  xmlns="http://schemas.openehr.org/v1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="COMPOSITION" archetype_node_id="openEHR-EHR-COMPOSITION.test_all_datatypes.v1">
  <name xsi:type="DV_TEXT">
    <value>Test all datatypes</value>
  </name>
  <uid xsi:type="OBJECT_VERSION_ID">
    <value>c8a0a6ef-a006-497a-b674-c1e595c30303::CABOLABS_EHR_SERVER::1</value>
  </uid>
  <archetype_details>
    <archetype_id>
      <value>openEHR-EHR-COMPOSITION.test_all_datatypes.v1</value>
    </archetype_id>
    <template_id>
      <value>test_all_datatypes.en.v1</value>
    </template_id>
    <rm_version>1.0.2</rm_version>
  </archetype_details>
  <language>
    <terminology_id>
      <value>ISO_639-1</value>
    </terminology_id>
    <code_string>es</code_string>
  </language>
  <territory>
    <terminology_id>
      <value>ISO_3166-1</value>
    </terminology_id>
    <code_string>UY</code_string>
  </territory>
  <category>
    <value>event</value>
    <defining_code>
      <terminology_id>
        <value>openehr</value>
      </terminology_id>
      <code_string>433</code_string>
    </defining_code>
  </category>
  <composer xsi:type="PARTY_IDENTIFIED">
    <name>Dr. Pablo Pazos</name>
  </composer>
  <context>
    <start_time>
      <value>2021-09-03T21:06:07.424Z</value>
    </start_time>
    <setting>
      <value>Hospital Montevideo</value>
      <defining_code>
        <terminology_id>
          <value>openehr</value>
        </terminology_id>
        <code_string>229</code_string>
      </defining_code>
    </setting>
  </context>
  <content xsi:type="OBSERVATION" archetype_node_id="openEHR-EHR-OBSERVATION.test_all_datatypes.v1">
    <name xsi:type="DV_TEXT">
      <value>Blood Pressure</value>
    </name>
    <language>
      <terminology_id>
        <value>ISO_639-1</value>
      </terminology_id>
      <code_string>es</code_string>
    </language>
    <encoding>
      <terminology_id>
        <value>UNICODE</value>
      </terminology_id>
      <code_string>UTF-8</code_string>
    </encoding>
    <subject xsi:type="PARTY_IDENTIFIED">
      <external_ref>
        <id xsi:type="HIER_OBJECT_ID">
          <value>11111111-1111-1111-1111-111111111111</value>
        </id>
        <namespace>DEMOGRAPHIC</namespace>
        <type>PERSON</type>
      </external_ref>
    </subject>
    <data archetype_node_id="at0001">
      <name xsi:type="DV_TEXT">
        <value>history</value>
      </name>
      <origin>
        <value>2021-09-03T21:06:07.425Z</value>
      </origin>
      <events xsi:type="POINT_EVENT" archetype_node_id="at0002">
        <name xsi:type="DV_TEXT">
          <value>any event</value>
        </name>
        <time>
          <value>2021-09-03T21:06:07.425Z</value>
        </time>
        <data xsi:type="ITEM_TREE" archetype_node_id="at0003">
          <name xsi:type="DV_TEXT">
            <value>Arbol</value>
          </name>
          <items xsi:type="ELEMENT" archetype_node_id="at0011">
            <name xsi:type="DV_TEXT">
              <value>Count</value>
            </name>
            <value xsi:type="DV_COUNT">
              <magnitude>4</magnitude>
            </value>
          </items>
        </data>
      </events>
      <events xsi:type="POINT_EVENT" archetype_node_id="at0002">
        <name xsi:type="DV_TEXT">
          <value>any event</value>
        </name>
        <time>
          <value>2021-09-03T21:06:07.425Z</value>
        </time>
        <data xsi:type="ITEM_TREE" archetype_node_id="at0003">
          <name xsi:type="DV_TEXT">
            <value>Arbol</value>
          </name>
          <items xsi:type="ELEMENT" archetype_node_id="at0011">
            <name xsi:type="DV_TEXT">
              <value>Count</value>
            </name>
            <value xsi:type="DV_COUNT">
              <magnitude>5</magnitude>
            </value>
          </items>
        </data>
      </events>
      <events xsi:type="POINT_EVENT" archetype_node_id="at0002">
        <name xsi:type="DV_TEXT">
          <value>any event</value>
        </name>
        <time>
          <value>2021-09-03T21:06:07.425Z</value>
        </time>
        <data xsi:type="ITEM_TREE" archetype_node_id="at0003">
          <name xsi:type="DV_TEXT">
            <value>Arbol</value>
          </name>
          <items xsi:type="ELEMENT" archetype_node_id="at0011">
            <name xsi:type="DV_TEXT">
              <value>Count</value>
            </name>
            <value xsi:type="DV_COUNT">
              <magnitude>6</magnitude>
            </value>
          </items>
        </data>
      </events>
    </data>
  </content>
</composition>

And I'm trying to access this value: c8a0a6ef-a006-497a-b674-c1e595c30303::CABOLABS_EHR_SERVER::1

@develohpanda
Copy link
Contributor

develohpanda commented Sep 8, 2021

Thanks @ppazos, that'll be very helpful to debug, alongside the other examples in this issue.

Unfortunately I don't have any timeframe for when this might be fixed (right now), on looking through https://github.com/goto100/xpath there doesn't appear to be a straightforward solution using this, so we might need to explore other libraries. I am certainly available and happy to assist in case anybody wants to pick this up! 🙌🏽

@ppazos
Copy link

ppazos commented Sep 8, 2021

I'm ignorant about libraries for JS development specially for desktop apps. Though if there is a DOM implemented somewhere, it might have XPath https://developer.mozilla.org/en-US/docs/Web/XPath/Introduction_to_using_XPath_in_JavaScript

@rippo
Copy link

rippo commented Feb 8, 2022

I ran into this issue but to help others, the XML API returns this. In my case I need to get the Guid, notice I have a ns inside of TicketHeader.

To get you can use the following xPath, HTH someone who hits this issue

//*[local-name(.)="Guid"]/text()

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
	xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Header>
		<TicketHeader
			xmlns="http://www.webcrm.com/">
			<Guid>2f6931c2-f2f6-4780-99bd-XXXXXXX</Guid>
		</TicketHeader>
	</soap:Header>
	<soap:Body>
		<AuthenticateResponse
			xmlns="http://www.webcrm.com/">
			<AuthenticateResult>
				<Message />
				<Code>0</Code>
			</AuthenticateResult>
		</AuthenticateResponse>
	</soap:Body>
</soap:Envelope>

@myst3k
Copy link

myst3k commented Jul 12, 2022

Ran into this issue and spent many more hours than I would have liked to try to authenticate with Tableau on further requests. Following @rippo example.

/*[name()='tsResponse']/*[name()='credentials']/@token

<tsResponse
	xmlns="http://tableau.com/api"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_16.xsd">
	<credentials token="mySecretToken" estimatedTimeToExpiration="364:23:49">
		<site id="1234" contentUrl="myAppName"/>
		<user id="5678"/>
	</credentials>
</tsResponse>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-bug Bug: general classification N-help Needs: Help S-verified Status: Verified by maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants