cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
593
Views
0
Helpful
3
Replies

Help needed for Get XML document Data

vduprez
Level 1
Level 1

Dear all,

I need to find the phone number (0123456789) in an XML document like this one:

<?xml version="1.0" encoding="UTF-8" ?>

<daily>

<team id="4"><oncall1 id="56">0123456789</oncall1></team>

</daily>

In the Get XML document I have configured the following XML Path

"/descendant::daily/child::team[attribute::id='TEAMID' ]/child::oncall1"

where TEAMID is set to 4

and I have a NULL result !!!!

the goal is to perform

"/descendant::daily/child::team[attribute::id=' " + TEAMVALUE + " ' ]/child::oncall1"

where TEAMVALUE is a variable string.

Please help me finding the issue or at least a way to debug this as I don't know how to debug this :-)

Thanks in advance

Vincent.

3 Replies 3

Anthony Holloway
Cisco Employee
Cisco Employee

This is all you should need:

"//team[@id=" + TEAMVALUE + "]/oncall1"

Where TEAMVALUE is an int variable which holds your team ID.

What you can do to debug first, is set this string to a variable, then reactive debug your script, making sure the result looks like this:

"//team[@id=4]/oncall1"

Because the ID value is numeric, the single quotes are not needed.  Also, the double forward slash, skips the root element, and just says: "find me a team node whose attribute equals 4."  Followed by single forward slash and the oncall1 node name, saying: and return the value of the child node oncall1."

Here's an OK reference for learning some XPATH

http://www.w3schools.com/XPath/xpath_syntax.asp

Dear Anthony,

thanks for your quick answer. I still have a NULL result but I will have a look to the link you provide me to avoid disturbing you for nothing.

thanks again. I will let everybody know the result...

Regards,

Vincent.

As another measure of troubleshooting, you shold create a brand new script for just testing your xpath.  Then, you can hard code values, and use active debugging versus reactive debugging.

The minimums would be:

Variables:

Document xml = doc[my_xml_doc.xml]

String xpath_target = "//team[@id=4]/oncall1"

String xpath_result = ""

Steps:

xml = Create XML Document(xml)
xpath_result = Get XML Document Data(xml, xpath_target)

Good luck, and let us know.