need help with XML Path syntax

Answered Question
Jun 29th, 2010

Consider the following xml document below:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<CALLINGNUMBERBERS>

     <CALLINGNUMBER ID='1'>

          <NUMBER>1234567890</NUMBER>

          <NAME>JONNY</NAME.

     </CALLINGNUMBER>

     <CALLINGNUMBER ID='2'>

          <NUMBER>8991234567</NUMBER>

          <NAME>JONNYHOME</NAME>

     </CALLINGNUMBER>

     <CALLINGNUMBER ID='3'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='4'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='5'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='6'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='7'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='8'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='9'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='10'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='11'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='12'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='13'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='14'>""</CALLINGNUMBER>

     <CALLINGNUMBER ID='15'>""</CALLINGNUMBER>

</CALLINGNUMBERBS>

I need to use the Get XML Document Data function to retrieve the following the number value and the name value as a string.  I understand that this has to be two separate requests.  It should be something like below.
"/descendant::CALLINGNUMBERS/child::CALLINGNUMBER[attribute::ID='" + callingNumberID.toString() + "']"
I have this problem too.
0 votes
Correct Answer by Anthony Holloway about 6 years 6 months ago

Your two documents are different.  One has SOBERSTAFF (really?) as the root node, and one doesn't.  You may just be mixing up your documents.  If you're not, click the refresh icon on the document  in the repository.

Also, based on your last xml document posting this would net you the same:

//callingnumber[@id='1']/Number

//callingnumber[@id='1']/Name

The double forward slash indicates a search within the document

The [@key=value] indicates an attribute predicate match

The last /Number or /Name indicates a relative node select from the match preceding

You don't need all the descendant and child syntax in there either.

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (2 ratings)
Loading.
WSonnylal Tue, 06/29/2010 - 12:30

So I found this great tool that let's me evaluate XPATH expressions against an XML doc.  The tool is here http://www.xmlme.com/XpathTool.aspx

Now using this tool and the following XPATH expression

"descendant::SOBERSTAFF/child::CALLINGNUMBERS/child::CALLINGNUMBER[attribute::ID=1]/child::NUMBER"

against the following XML DOC...

<?xml version="1.0" encoding="ISO-8859-1" ?>

    

         

               1234567890

               JONNY

         

         

               8991234567

               JONNYHOME

         

          ""

          ""

          ""

          ""

          ""

          ""

          ""

          ""

          ""

          ""

          ""

          ""

          ""

    

    

          6412

          5551212

          ""

          ""

          ""

          ""

          ""

         

         

         

         

         

         

         

         

    

I'm able to get back the result that I want namely the value 1234567890 using the xpath query expression tool so my path is correct for the tool.  Now I can put this same expression into UCCX in the Get XML Document Data step and it accepts it.  But the value I get back is NULL when i run the script.  Very confused.

Message was edited by: WSonnylal

Correct Answer
Anthony Holloway Tue, 06/29/2010 - 13:50

Your two documents are different.  One has SOBERSTAFF (really?) as the root node, and one doesn't.  You may just be mixing up your documents.  If you're not, click the refresh icon on the document  in the repository.

Also, based on your last xml document posting this would net you the same:

//callingnumber[@id='1']/Number

//callingnumber[@id='1']/Name

The double forward slash indicates a search within the document

The [@key=value] indicates an attribute predicate match

The last /Number or /Name indicates a relative node select from the match preceding

You don't need all the descendant and child syntax in there either.

WSonnylal Tue, 06/29/2010 - 14:13

Thanks for the help Anthony.  I tried it like you described and I'm still getting a NULL value response.  Not sure what it could be so I'm going to rebuild the XML file to see if it helps.

steakandeggs Fri, 10/29/2010 - 14:24

Thanks Anthony. Where did you pick up your knowledge of XML syntax? Any book you recommend, or Internet

resource? There is this http://www.w3.org/TR/xpath/, and it is great reference, but some examples would be good.

Actions

This Discussion