XPath providing Object and not a String

Friends, im trying to fetch the url from this XML

i tried like this but im not getting correct output

pls help me out

Hi @kgbheem,

To help others to assist you, many find it beneficial when the raw text or an example file to work with where possible, this way someone can spend less time speculating or back and forth banter to mimic the particular scenario.

I mocked up part of the XML from your image

<MultimapPresentation version="1.0.41" client="dealerdirect">
  <locationData type="storefinder">
    <locationCount>1</locationCount>
    <totalRecords>1</totalRecords
    <prevPageUrl />
    <nextPageUrl />
    <location id="1">
      <record>
        <param name="busid">2640</param>
        <param name="zip">06374-2034</param>
        <param name="url">http://www.google.ca</param>
        <param name="preown">1</param>
      </record>
    </location>
  </locationData>
</MultimapPresentation>

In your original XPath Query

This would be searching the XML for any matching <record> nodes that contain with a child-node <name> with a value of url.

The expected XML would look something like the following and would return an Object of matching the query, in this case just the 2nd <record>.

<root>
  <record>
    <name>Bob</name>
  </record>
  <record>
    <name>url</name>
    <age>107</age>
  </record>
</root>

If you were to wrap the query in a string() e.g. string(//record[name='url']) it would return the string instance of each child node’s value concatenated together. e.g. url107.

There are many ways to go about querying with XPath, looking back at your example, the absolute query would be:

//MultimapPresentation/locationData/location/record(0)/param[name='url']

Shortening the query to look for matching <record> that contains <param name="url">... you’re missing a node level along with reference to the attribute.

//record/param[name='url']

finally, you’d want to convert XPath object to a string using the fn:string() function turning the query into

string(//record/param[name='url'])

Alternatively, you can also use the XMLDocument methods such as XPathSelectElements if you didn’t want to use the Execute XPath activity.

Hope that clears it up!

4 Likes

Thank you so much @codemonkee.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.