Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

JSON Databank Xpath

reactancexl
reactancexl Posts: 181

I am trying to get a value from xpath and when I "Evaluate XPath" I get the correct value. When I execute at runtime the value = null on the console. If I hard code the value(position) it writes to console.
Here is my xpath: /root/addressRelations/item[id/addressTypeId/text()='PR']/address[1]/city/text()

I am using 2024.1 and 2024.2. I have done many xpaths like this with conditions on a repeating segment with no issues before. Is there a setting somewhere? Thoughts?

Best Answer

  • benken_parasoft
    benken_parasoft Posts: 1,331 ✭✭✭
    edited March 26 Answer ✓

    item[id/addressTypeId/text()='PR']

    The value in your JSON is "PR " (two spaces) and not "PR". You could do one of the following instead:

    item[id/addressTypeId/text()='PR  ']
    

    or

    item[normalize-space(id/addressTypeId/text())='PR']
    

    when I "Evaluate XPath" I get the correct value

    The button operates on a pretty-printed version of the XML representation where whitespace is normalized. At runtime, the XPath operates on the original message.

Answers

  • benken_parasoft
    benken_parasoft Posts: 1,331 ✭✭✭
    edited March 25

    Can you provide a sample JSON document? What the XPath will or will not match really depends on what it is being evaluated against.

  • reactancexl
    reactancexl Posts: 181

    attached is the json.

  • reactancexl
    reactancexl Posts: 181

    that worked. The learning gained here is to always use "normalize-space". thx