The CreatorCon Call for Content is officially open! Get started here.

Parsing XML Response

mdidrikson
Kilo Contributor

Hello,

I have a business rule that makes a call to an external web service and receives an XML response. The response document returned is quite large (see attached document). I am having some issues parsing this XML document. Here is the code that I am using to parse the response document:



var response = request.getResponseDoc();
gs.log("Get Tickets response from Savvis: " + response);

gs.log("Parse the response");

//PARSE THE RESPONSE
try {
var savvisXML = new XMLDocument(response);
} catch (e) {
gs.log("Error parsing XML response from Savvis: " + e.toString());
}

I am receiving the following error:

Error parsing XML response from Savvis: java.lang.NullPointerException

My guess is the issue is with the

<![CDATA[
tags in the response document. If I make this call and these fields are not included, I am able to parse the document.

Couple of questions I have:

1. Is there a way to parse an XML document that contains the

<![CDATA[
tags?
2. Is there a good way to loop through a large XML document such as this one? I would like to grab the "key" and "value" elements from this document.

Thanks for your help!

Mark Didrikson

18 REPLIES 18

Hello,

I've got a business rule that makes a web service call to retrieve a large amount of data and then performs so actions on the responses. The issue I'm having is when I call a specific web service operation at an outside vendor, I'm not able to parse their response using the XMLDocument function. I believe the issue is with some of the free-form elements in the response document.

Here is the code I am using to parse the response:



gs.log("Parse the response");

//PARSE THE RESPONSE
try {
var savvisXML = new XMLDocument(response);
} catch (e) {
gs.log("Error parsing XML response from Savvis: " + e.toString());
}


I have attached the response XML I'm receiving from this call. It is a pretty large document.

Here is what I'm seeing in the logs:

After parse the response
Error parsing XML response from Savvis: java.lang.NullPointerException
formationParse the response

I can see from the log that Service-Now is receiving the response XML successfully.

Does anyone know why Service-Now would be unable to parse this XML document?

Thanks!

Mark Didrikson


I took your xml doc and ran a script against it and it imported just fine. Actually, I was able to use XPATH to browse sub-elements that contained CDATA.

I would check to make sure that your "response" variable contains the full, unaltered xml that you are expecting.

-John


Hi John,

I can see the full xml response in the log file. It appears to be complete.

Is there some other type of validation I can run against the response variable before I try and parse it?

Thanks!

Mark Didrikson


I often use this handy dandy tool on fryo.com:

http://www.fryo.com/makePretty.php

-John


It's interesting, if I take the XML response document straight from the Service-Now log file and try to run it through the validation tool you provided, it returns some exceptions. I have attached the XML I copied from the Service-Now log to this message.

However, if I make my web service call from within SOAP UI and I copy this response XML document into the validation tool, it validates successfully. I have attached this XML document as well.

Thanks.

Mark Didrikson