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.
Can anyone please provide a solution?
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:
Former Member -
I think the syntax checks out. It has to do with namespaces.https://www.w3schools.com/xml/xml_namespaces.asp
Fair enough - though it looks like the current version of xpathsnippet() doesn't handle this, so my suggested workaround might still be necessary.
Appian does handle this.Performing xpath on xml with namespaces is just a bit more complicated than parsing xml without namespaces.This is well documented on the web; it's a common problem people have with xpath, and discussed repeatedly on sites like stackoverflow.sayalip I expect if you do a bit more research on the topic of XML with namespaces and xpath, you'll have your solution.
Robert Shankin said:Appian does handle this.
Can you confirm this? Because when I tried calling xpathsnippet() on the original poster's code, I got the following pink error even when just using the xpath "select all" command:
Additionally, playing with it in the expression editor, I can't get any combination of syntax for the xpath expression to not return this error message when the input string has the "a:" delimiters. Am I still just doing something wrong?
The namespace prefix is not defined in the original post.
Thanks, I see what you mean now - I altered my original sample code to include a fake prefix definition and it seems to work now.
Yup. As I noted, xpath seems super easy right up until namespaces are involved.
Discussion posts and replies are publicly visible
© 2020 Appian. All rights reserved.