cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2984
Views
15
Helpful
12
Replies

UCCX XML file parsing failed

best2sons
Level 1
Level 1

Hi Experts,

My customer has some requirement of distributing CSQ by giving CUSOMER Number and provided below format.

 

1.  first xml file format and parsing error

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

<CUSTOMERS>
<CUSTOMER ID="100012">Credit_PPD_5</CUSTOMER>
<CUSTOMER ID="100013">Credit_PPD_4</CUSTOMER>

 

And I wanted to get 100012 and Credit_PPD_4 using below xpath.

"/descendant::CUSTOMERS/child::CUSTOMER[attribute::ID='"

"/descendant::CUSTOMERS/child::CUSTOMER[attribute::ID='" + CustormerNumberEntered + "']" 

 

Just before get XML Document Data step, final xpath string is like.

"/descendant::CUSTOMERS/child::CUSTOMER[attribute::ID="

"/descendant::CUSTOMERS/child::CUSTOMER[attribute::ID='100013']"

But I got runtime error  of Xparser exception as attached.

 

2.   second xml file format and parsing error

And I need to work another format of XML file and put xpath as below.

<? xml version = "1.0" encoding = "UTF-8" ?>
<CUSTOMERS>
  <RECORD>
  <CUSTOMERID>100012</CUSTOMER>
  <CSQID>Credit_PPD_5</CSQID>
  </RECORD>
  <RECORD>
  <CUSTOMERID>100013</CUSTOMER>
  <CSQID>Credit_PPD_4</CSQID>
  </RECORD>
  <RECORD>
  <CUSTOMERID>100014</CUSTOMER>
  <CSQID>Credit_PPD_4</CSQID>
  </RECORD>
</CUSTOMERS>

 

 


"/descendant::CUSTOMERS/child::RECORD/child::CUSTOMERID"
"/descendant::CUSTOMERS/child::RECORD/child::CSQID"

 

 

But both of xpath also get running-time error message of parser exception error.

 

Please help me to get right Xpath command to get right information of CUSTOMER ID and CSQID.

Thanks in advance.

 

Jason

 

 

 

 

 

 

 

 

2 Accepted Solutions

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee

I don't quite follow what you posted.  Either there is a formatting error on the web page here or you typed in some errors on your own.

 

Basically, the example XML should look like this:

<?xml version="1.0" encodng="utf-8"?>
<customers>
  <customer id="100012">
    <csq>Credit_PPD_5</csq>
  </customer>
  <customer id="100013">
    <csq>Credit_PPD_4</csq>
  </customer>
</customers>

This format keeps your Xml eXtensible, which allows you to add other things to it without having to rewrite your script.

Example:

Extending the XML to include a customer priority to be assigned to the calling contact.

<?xml version="1.0" encodng="utf-8"?>
<customers>
  <customer id="100012">
    <csq>Credit_PPD_5</csq>
    <priority>5</priority>
  </customer>
  <customer id="100013">
    <csq>Credit_PPD_4</csq>
    <priority>10</priority>
  </customer>
</customers>

You could include this new priority element without having to rewrite your script.  And then you can choose to use it or not in your existing scripts or in your new scripts.  Without the extinsible feature of XML, your prior XPATH to get the CSQ name would have been:

//customer[@id='100012']

And then modifying your XML to include support for a priority would have changed it to:

//customer[@id='100012']/csq

Causing a script change.

However, starting off extensible friendly, your XPATH would have always been this, and never changed:

//customer[@id='100012']/csq

I hope that helped explain it for you.

View solution in original post

Gergely Szabo
VIP Alumni
VIP Alumni

Hi,

your first XML seems to be broken. Here is the correct version:

<?xml version="1.0" encoding="UTF-8" ?>
<CUSTOMERS>
<CUSTOMER ID="100012">Credit_PPD_5</CUSTOMER>
<CUSTOMER ID="100013">Credit_PPD_4</CUSTOMER>
</CUSTOMERS>

I assume you want to get the text value of a CUSTOMER element if the ID element matches a string (e.g. if the input parameter is 100013 you want to get CREDIT_PPD_4).

If so, you are probably looking for the following XPath expression:

"//CUSTOMER[@ID=100012]/"

In your case, it's "//CUSTOMER[@ID=" + CustormerNumberEntered + "]"

 

Your second XML is broken as well. Here is the correct version:

<?xml version="1.0" encoding="UTF-8" ?>
<CUSTOMERS>
  <RECORD>
  <CUSTOMERID>100012</CUSTOMERID>
  <CSQID>Credit_PPD_5</CSQID>
  </RECORD>
  <RECORD>
  <CUSTOMERID>100013</CUSTOMERID>
  <CSQID>Credit_PPD_4</CSQID>
  </RECORD>
  <RECORD>
  <CUSTOMERID>100014</CUSTOMERID>
  <CSQID>Credit_PPD_4</CSQID>
  </RECORD>
</CUSTOMERS>

I can only assume you want the same thing again, getting the CSQID if a CUSTOMERID matches. In that case, the XPath expression you are looking for is:

"//RECORD[CUSTOMERID=100012]/CSQID" or if the input parameter is stored as a variable named CustormerNumberEntered:

"//RECORD[CUSTOMERID="+ CustormerNumberEntered + "]/CSQID"

G.

View solution in original post

12 Replies 12

Anthony Holloway
Cisco Employee
Cisco Employee

I don't quite follow what you posted.  Either there is a formatting error on the web page here or you typed in some errors on your own.

 

Basically, the example XML should look like this:

<?xml version="1.0" encodng="utf-8"?>
<customers>
  <customer id="100012">
    <csq>Credit_PPD_5</csq>
  </customer>
  <customer id="100013">
    <csq>Credit_PPD_4</csq>
  </customer>
</customers>

This format keeps your Xml eXtensible, which allows you to add other things to it without having to rewrite your script.

Example:

Extending the XML to include a customer priority to be assigned to the calling contact.

<?xml version="1.0" encodng="utf-8"?>
<customers>
  <customer id="100012">
    <csq>Credit_PPD_5</csq>
    <priority>5</priority>
  </customer>
  <customer id="100013">
    <csq>Credit_PPD_4</csq>
    <priority>10</priority>
  </customer>
</customers>

You could include this new priority element without having to rewrite your script.  And then you can choose to use it or not in your existing scripts or in your new scripts.  Without the extinsible feature of XML, your prior XPATH to get the CSQ name would have been:

//customer[@id='100012']

And then modifying your XML to include support for a priority would have changed it to:

//customer[@id='100012']/csq

Causing a script change.

However, starting off extensible friendly, your XPATH would have always been this, and never changed:

//customer[@id='100012']/csq

I hope that helped explain it for you.

Hi Anthony, you won the machine gun typing competition! cheeky

G.

 

Hi Anthony,

And after seeing your guys's answer, I noticed that there was some space here.

I gave to customer of sample of working template but customer broken the file and I was suffering without any sense, I think it is really difficult to notice, thanks again.

I have basic question before testing.

1. What is exact xpath value of getting "100012" from each XML file ?

I tried to get but failed, so I changed to use caller input as index, but want to get "10012" from xml itself not from user input.

2. in your answer of 

//customer[@id='100012']

 

is it single(') or double(") for '100012' ?

I am totally new for xml and java,so I seek your understanding.

 

I will update later testing with your answer. 

Thanks.

Jason.

 

Hi Expert,

I changed the Xml file and tested with your Xpath command,  but it showed same exception error as experienced  before.

I opened Cisco TAC, but he told Cisco TAC is not familiar of this kind of customized script and not supposed to do.

He tried to help, but it seems it would be difficult for him and he suggested me to get help from this forum  (^^;)

 

So I attached this script file and xml file, please check and let me know what is the root cause of this issue.

 

Thanks 

Jason

 

 

Hi,

please post a screenshot of the script - at least the relevant part.

The XML file is broken again. Attached is the corrected version.

I believe you should grasp at least the basics of XML and XML processing. Here's some quick guides to start with:

http://www.w3schools.com/xml/default.ASP

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

G.

Hi Gergely,

 

Thanks of your supports, I am really appreciated it.

I opened TAC but they didn't know, you and Anthony made it worked.

I was so busy but had to comeback to give right rating to both of you.

 

BTW, i have one more question.

If I use below Xpath and caller doesn't give any input, then it is going to same java exception error.

"//CUSTOMER[@ID=" + CustormerNumberEntered + "]"

under file of below format.

<?xml version="1.0" encoding="utf-8"?>
<CUSTOMERS>
<CUSTOMER ID="100012">Credit_PPD_5</CUSTOMER>
<CUSTOMER ID="100013">Credit_PPD_4</CUSTOMER>
<CUSTOMER ID="100014">Credit_PPD_4</CUSTOMER>
<CUSTOMER ID="100016">Credit_PPD_4</CUSTOMER>

</CUSTOMERS>

 

How can i have error control in case callers don't give any input for ID ?

Thanks of your answer in advance.

 

Jason.

 

Gergely Szabo
VIP Alumni
VIP Alumni

Hi,

your first XML seems to be broken. Here is the correct version:

<?xml version="1.0" encoding="UTF-8" ?>
<CUSTOMERS>
<CUSTOMER ID="100012">Credit_PPD_5</CUSTOMER>
<CUSTOMER ID="100013">Credit_PPD_4</CUSTOMER>
</CUSTOMERS>

I assume you want to get the text value of a CUSTOMER element if the ID element matches a string (e.g. if the input parameter is 100013 you want to get CREDIT_PPD_4).

If so, you are probably looking for the following XPath expression:

"//CUSTOMER[@ID=100012]/"

In your case, it's "//CUSTOMER[@ID=" + CustormerNumberEntered + "]"

 

Your second XML is broken as well. Here is the correct version:

<?xml version="1.0" encoding="UTF-8" ?>
<CUSTOMERS>
  <RECORD>
  <CUSTOMERID>100012</CUSTOMERID>
  <CSQID>Credit_PPD_5</CSQID>
  </RECORD>
  <RECORD>
  <CUSTOMERID>100013</CUSTOMERID>
  <CSQID>Credit_PPD_4</CSQID>
  </RECORD>
  <RECORD>
  <CUSTOMERID>100014</CUSTOMERID>
  <CSQID>Credit_PPD_4</CSQID>
  </RECORD>
</CUSTOMERS>

I can only assume you want the same thing again, getting the CSQID if a CUSTOMERID matches. In that case, the XPath expression you are looking for is:

"//RECORD[CUSTOMERID=100012]/CSQID" or if the input parameter is stored as a variable named CustormerNumberEntered:

"//RECORD[CUSTOMERID="+ CustormerNumberEntered + "]/CSQID"

G.

Hi Gergely,

Thanks of your valuable information, I will test tomorrow and update with proper rating.

And after seeing your answer, I noticed that there was some space here and there of the xml file given by customer, I think it is really difficult to notice, thanks again.

I have basic question before testing.

1. What is exact xpath value of getting "100012" from each XML file ?

I tried to get but failed, so I changed to use caller input as index, but want to get "10012" from xml itself not from user input.

 

2. for your second answer of xml file,

As I have another nested parent element of "CUSTOMERS",

do I need to put like below ?

I am really new to XML and java, so I have to ask in detail.

 

"//CUSTOMER/RECORD[CUSTOMERID=100012]/CSQID"

 

3. if file is not broken,

Then below xpath might be fine ?

"/descendant::CUSTOMERS/child::CUSTOMER[attribute::ID='" + CustormerNumberEntered + "']" 

 

Thanks in advance and I will update you after tomorrow testing.

Jason.

Hi,

I am already at home so I can't test this with a real UCCX at this moment, but here's a try:

RE 1: how to get 100012 from each XML file - I am not quite sure why you need this, you usually search by something and expect a result, but anyway:

- //CUSTOMER[1]/@ID

- //CUSTOMER[@ID=100012]/@ID

from the first XML, and

- //RECORD[1]/CUSTOMERID

- //RECORD[CUSTOMERID=100012]/CUSTOMERID

Again, no guarrantees.

RE 2: The CUSTOMERS is actually the root element, so all other elements belong to it.

Let me explain the XPath expression "//CUSTOMER/RECORD[CUSTOMERID=100012/CSQID":

//CUSTOMER means "search for any CUSTOMER element";

/RECORD[CUSTOMERID=100012] where the above (any) CUSTOMER element has a child element named RECORD, of which child element named CUSTOMERID has the following text: 100012;

/CSQID - and get the text out of the above found element's child element named CSQID.

RE 3: I don't really like this XPath notation as it is too verbose, but yes, if you apply that XPath to the first XML file, it would yield Credit_PPD_5.

G.

 

 

 

Gergely Szabo
VIP Alumni
VIP Alumni

Hi,

yes, that's expected, since if CustormerNumberEntered contains a zero length string, it yields an invalid XPath expression: "//CUSTOMER[@ID=]".

The easiest and most elegant way of handling exceptions is not letting them happen.

For instance, you can insert an If step with the following expression:

If (CustormerNumberEntered.length()==0)

The "True" exit would lead to some special treatment, perhaps a message: "I'm sorry, you did not enter any ID please repeat" and send the execution pointer back to the beginning. This would skip the XML processing part which is kind of costly.

G.

Hi Gergely,

 

Thanks of your quick answer all the time,

Using another IF step I already configured before sending this.

I just want to know how to remove this kind of unexpected error on XML and Xpath side like put

//CUSTOMER[@ID=null]  or //CUSTOMER[@ID="null"] with last line with <CUSTOMER ID><CUSTOMER> ?

 

Thanks

Jason

 

Other than additional IF line, can I have another way with CED is "0"

Hi,

no, you don't have to create such constructs. Using an If step to check the length of the variable to be inserted in the XPath expression, and skipping the XML processing part altogether is the easiest and it puts the least load on the system.

G.

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: