09-09-2012 11:26 PM
Team,
I'm doing a web service execute which produces the following output:
<RetrieveRelationshipKeysListResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" status="SUCCESS" message="Success" schemaRevisionDate="2012-08-31" schemaRevisionLevel="1" returnCode="0" query="">
- <keys xmlns="http://schemas.hp.com/SM/7">
</keys>
</RetrieveRelationshipKeysListResponse>
All I wish to do is collect the content of the ParentCI node using an XPath query: //ParentCI
But the XPath operation simply says it can't find it. I haven't defined any namespaces and perhaps this could be the problem but as you can see the node uses the default namespace.
Perhaps I need to define all of them?
--
Ryan
09-10-2012 05:39 AM
//ParentCI is not the proper XPath for that XML. Two things need to happen to get that to work....
1) Remove the XMLNS string from the keys tag, so take out
xmlns="
this is not too hard with the replace string function, just do a replace string of that part and replace it with a blank space.
This is not just in CPO, if you tried to use this same part in Notepad++ with it's *standard* XML tools plugin, it would not work with that XMLNS in it.
2) Run the proper XPath Query of
/RetrieveRelationshipKeysListResponse/keys/ParentCI
I was able to do this in CPO without issue. I would suggest you go get Notepad++ and the XML Tools plugin for it as well. This allows you to test your XML, XSLs, and XPath queries before you input them into other products. Highly useful for testing and debugging.
-Shaun
09-10-2012 03:59 PM
Chris,
A few points:
Possibly both. I will try out the suggestion of removing the xmlns attribute in the keys node and see if that makes a difference.
I have also managed to solve it with ah XSLT transform outputting as text as an alternative, after using a regex to extract just the ParentCI node. I will also try to see if I can use XSLT alone to extract the contents of the ParentCI node as that would be a bit more elegant.
Here is my XSLT for reference:
What do you think?
--
Ryan
09-11-2012 06:16 AM
Hello, Ryan!
CPO absolutely supports double slash, and all the standard XPath constructs. The issue with your XPath query of //ParentCI is exactly what you suspected (the namespaces).
Let's look at this XML closely...
What xlms="blah" in the key element means is that there is a "default" (unnamed) namespace defined for all elements and sub-elements within key tag. So the proper names for all those tags are not keys, ParetCI and RelationshipName, but the ones with a namespace "prefix". What is clearly confusing, is that while the XML does define the namespace, it omits (defaults) the prefix.
Given this XML, when you are searching for any tag within tag key you need to "prefix" your search with a namespace.
So what you need to do to make your query work in XPath Query activity is
And that should produce the answer you are looking for.
09-17-2012 10:20 PM
Svetlana,
I send greetings from Mike Whiteley.
The solution above worked a treat. XPath matches now work as expected. Thanks again.
--
Ryan
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide