cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
6444
Views
10
Helpful
7
Replies

UCCX 8.5.1 "Get XML Document Data" always returns the data of the first record

r.rung
Level 1
Level 1

Hello Support Cummunity,

i have a XML file with the following content:

<csv_data_records>

     <record>

          <title/>

          <firstname>numberone</firstname>

          <lastname>numberone</lastname>

          <phone>11111</phone>

     </record>

     <record>

          <title/>

          <firstname>number2</firstname>

          <lastname>number2</lastname>

          <phone>22222</phone>

     </record>

     <record>

          <title/>

          <firstname>number3</firstname>

          <lastname>number3</lastname>

          <phone>33333</phone>

     </record>

</csv_data_records>

my "Get XML Document Data" looks like this:   "/descendant::csv_data_records/child::record/child::phone"

in the first round it returns 11111 as phone number, thats ok, if this doesnt match to the caller i make a loop and make the "Get XML Document Data" a second time, but then it also returns 11111.

i remember it from the UCCXD Course that this works if i use a SQL Server. but why doesn't it work with XML?

with SQL Server it recognizes itself that this is the second query and returns the second value...

is there a hint to also achieve this with XML?

7 Replies 7

Anthony Holloway
Cisco Employee
Cisco Employee

You have to use an XPATH predicate like this:

//record[1]

//record[2]

etc.

Therefore, your xapth needs to be built at run time like this:

label Get Next Record

increment i

xpath_record = "//record[" + i + "]"

xpath_result = Get XML Document Data (xml_doc, xpath_record)

if (xpath_result != null && xpath_result.trim() != "")

  true

    /* Data Found - Store the data in the record variable */

    set record = xpath_result

    ...Your record processing steps go here...

    goto Get Next Record

  false

    /* No Data Found - End the loop */

    goto End of Record Set

label End of Record Set

Source for more info: http://www.w3schools.com/xpath/xpath_syntax.asp

EDIT: Added more detail to the script example.

ok thank you Anthony, i will try that.

Please write back and let everyone know if it worked, and if so, mark this solution as solved so others know if this is a good solution to follow or not.  Thanks.

This doesn't seem to work for me.  I have tried several variations of XPath, but [2] or more always comes up "null", even though the XML Document contains multiple records.

When calling record[1]. I pull up the first data.  No problems.  but, calling record[2] or record[3] or more, always just shows up null data.

I've tried using the absolute path (i.e. /descendant::root/child::childnode/child::datafield[2]).  i've also tried ( //datafield[2] ).

None seem to work.  Always come up null.  But, when i debug, and I look at the XML Document that I'm parsing, I verified all the nodes are there.

I found the problem.  Using this XML as example:

 

    Boring Stuff

    Boring Stuff2

 

    Cool Stuff

    Cool Stuff2

 


Now, using //data1[1] and using //data1[2] should work, but it didn't for me.   Instead, I had to use the array at the "Record" level rather than the data level.  In other words, to get both "Boring Stuff" and "Cool Stuff", I had to use the following XPath:

/descendant::Parent/child::Record[1]/child::data1

and

/descendant::Parent/child::Record[2]/child::data1

So, if I were to modify Anthony's script above:

label Get Next Record
increment i
xpath_record = "/descendant:Parent/child::Record[" + i + "]/child::data1"
xpath_result = Get XML Document Data (xml_doc, xpath_record)
if (xpath_result != null && xpath_result.trim() != "")
  true
    /* Data Found - Store the data in the record variable */
    set record = xpath_result
    ...Your record processing steps go here...
    goto Get Next Record
  false
    /* No Data Found - End the loop */
    goto End of Record Set
label End of Record Set


The i increment should work if you need an actual exemple:

Beautiful elegant solution.
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: