Parse XML response with xpathsnippet

hi,

I have an xml response containing tags like <a:IsSuccessful>true</a:IsSuccessful>. And I want to retrieve the value of a:IsSuccessful. 

I am trying below code but it throws an error-

xpathsnippet( pv!response, "//a:IsSuccessful/text()" )

When I try a tag without colon (like below) it works fine.

xpathsnippet("<IsSuccessful>true</IsSuccessful>","//IsSuccessful/text()")

Can anyone please provide a solution?

Parents
  • As far as I can tell, having a colon in the tag name ("a:") is either against XML best practices, or maybe even plainly not allowed.  Refer to the "Best Naming Practices" found here: https://www.w3schools.com/xml/xml_elements.asp

    If you have no control over the XML response you're needing to deal with, I suggest perhaps developing local-side sanitization rules to pass all the XML through first to get the tag names into a format that won't break xpathsnippet.  Maybe something along the lines of:

    xpathsnippet(
      substitute(
        "<a:isSuccessful>true</a:isSuccessful>",
        ":",
        "_COLON_"
      ),
      "//a_COLON_isSuccessful/text()"
    )

Reply
  • As far as I can tell, having a colon in the tag name ("a:") is either against XML best practices, or maybe even plainly not allowed.  Refer to the "Best Naming Practices" found here: https://www.w3schools.com/xml/xml_elements.asp

    If you have no control over the XML response you're needing to deal with, I suggest perhaps developing local-side sanitization rules to pass all the XML through first to get the tag names into a format that won't break xpathsnippet.  Maybe something along the lines of:

    xpathsnippet(
      substitute(
        "<a:isSuccessful>true</a:isSuccessful>",
        ":",
        "_COLON_"
      ),
      "//a_COLON_isSuccessful/text()"
    )

Children

 Discussion posts and replies are publicly visible