Parsing XML and not able to get the node value I want

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 02:54 PM
Hello Everyone!
I am trying to parse a value out of an XML response, and I can't seem to get it. The response is returning correctly to me as needed (verifying using tostring() as you see below), but when I try to grab the "RequesterID" value that I need, I always get a return value of "null". Code Snippet below as to how I'm trying to grab it, and I have also attached the response. Pretty sure this is something simple, but I'm missing it...
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(responseBody);
//gs.info(xmlDoc.toString());
gs.info(xmlDoc.getNodeText("//RequesterID"));
Thanks for any help!
Jason
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 03:20 PM
Hi Jason,
Have you tried gs.info(xmlDoc.getNodeText("//ServiceIncident/RequestedID"))

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 05:30 PM
Hi Venkat,
Thank you for the reply. I just tried this and I still get "null".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 03:32 PM
I got it to return '1177' with your code in scripts - background. I had to delete this line first though because it kept throwing an error when I left it in:
<?xml version="1.0" encoding="utf-8"?>
Error:
- org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
- at [row,col {unknown-source}]: [1,194]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 03:34 PM
So this is what I ran so you can try to reproduce it (Note: I deleted that line I mentioned above from line #5):
var responseBody = ' <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> ' +
' <s:Body> ' +
' <TESTResponse xmlns="http://tempuri.org/"> ' +
' <TESTResult> ' +
' <ServiceIncident> ' +
' <ProviderID>Test Ticket</ProviderID> ' +
' <RequesterID>1177</RequesterID> ' +
' <Transaction> ' +
' <Acknowledge>1</Acknowledge> ' +
' <StatusCode>0</StatusCode> ' +
' <Comment>No Errors Encountered</Comment> ' +
' <TransactionName>Problem_Submittal</TransactionName> ' +
' <TransactionType>2</TransactionType> ' +
' <TransactionDateTime>4/13/2016 6:20:25 PM</TransactionDateTime> ' +
' <TransactionNumber>1875869</TransactionNumber> ' +
' </Transaction> ' +
' </ServiceIncident> ' +
' </TESTResult> ' +
' </TESTResponse> ' +
' </s:Body> ' +
' </s:Envelope> ' ;
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(responseBody);
gs.print(xmlDoc.getNodeText("//RequesterID")); // 1177