- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 11:56 AM
I am trying to get the value of a node from a XML response, but its giving me the value null instead.
Here is the response:
XMLDOC: <?xml version="1.0" encoding="UTF-8"?><Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Body><ServiceIncident xmlns="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2"><RequesterID>IN28617860</RequesterID><ProviderID>INC0023912</ProviderID><Reporter><ReporterID/></Reporter><Transaction><Acknowledge>1</Acknowledge><StatusCode>0</StatusCode><Comment>Success - No Errors Encountered</Comment><TransactionName/><TransactionType>2</TransactionType><TransactionDateTime>2017-07-20T15:53:38.0z</TransactionDateTime><TransactionNumber>1500576818383</TransactionNumber><TransactionRouting>SYNC::TIGSNOINSR</TransactionRouting></Transaction></ServiceIncident></Body></Envelope>
Here is my Code xmldoc.getNodeText("//RequesterID")
And is returning null
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 12:18 AM
Hi Juliana,
Can you try below code? I verified it is working. You need to remove the starting "XMLDOC:" string as it is not part of the XML string.
========================
var xmlString = "<?xml version='1.0' encoding='UTF-8'?><Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Body>" +
"<ServiceIncident xmlns='http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2'><RequesterID>IN28617860</RequesterID><ProviderID>INC0023912</ProviderID>" +
"<Reporter><ReporterID/></Reporter><Transaction><Acknowledge>1</Acknowledge><StatusCode>0</StatusCode><Comment>Success - No Errors Encountered</Comment>" +
"<TransactionName/><TransactionType>2</TransactionType><TransactionDateTime>2017-07-20T15:53:38.0z</TransactionDateTime>" +
"<TransactionNumber>1500576818383</TransactionNumber><TransactionRouting>SYNC::TIGSNOINSR</TransactionRouting></Transaction></ServiceIncident></Body></Envelope>";
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(xmlString);
gs.print(xmlDoc.getNodeText("//RequesterID"));
========================
Cheers
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 12:18 AM
Hi Juliana,
Can you try below code? I verified it is working. You need to remove the starting "XMLDOC:" string as it is not part of the XML string.
========================
var xmlString = "<?xml version='1.0' encoding='UTF-8'?><Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Body>" +
"<ServiceIncident xmlns='http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2'><RequesterID>IN28617860</RequesterID><ProviderID>INC0023912</ProviderID>" +
"<Reporter><ReporterID/></Reporter><Transaction><Acknowledge>1</Acknowledge><StatusCode>0</StatusCode><Comment>Success - No Errors Encountered</Comment>" +
"<TransactionName/><TransactionType>2</TransactionType><TransactionDateTime>2017-07-20T15:53:38.0z</TransactionDateTime>" +
"<TransactionNumber>1500576818383</TransactionNumber><TransactionRouting>SYNC::TIGSNOINSR</TransactionRouting></Transaction></ServiceIncident></Body></Envelope>";
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(xmlString);
gs.print(xmlDoc.getNodeText("//RequesterID"));
========================
Cheers
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 05:34 AM
It did work fine with XMLDocument2, my question is why doesn't work for XMLDocument, for some reason, is it the encoding of the message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 12:26 AM
Works for me:
var xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
" <Body>" +
" <ServiceIncident xmlns=\"http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2\">" +
" <RequesterID>IN28617860</RequesterID>" +
" <ProviderID>INC0023912</ProviderID>" +
" <Reporter>" +
" <ReporterID />" +
" </Reporter>" +
" <Transaction>" +
" <Acknowledge>1</Acknowledge>" +
" <StatusCode>0</StatusCode>" +
" <Comment>Success - No Errors Encountered</Comment>" +
" <TransactionName />" +
" <TransactionType>2</TransactionType>" +
" <TransactionDateTime>2017-07-20T15:53:38.0z</TransactionDateTime>" +
" <TransactionNumber>1500576818383</TransactionNumber>" +
" <TransactionRouting>SYNC::TIGSNOINSR</TransactionRouting>" +
" </Transaction>" +
" </ServiceIncident>" +
" </Body>" +
"</Envelope>";
var xmldoc = new XMLDocument(xmlString);
var str = xmldoc.getNodeText("//RequesterID");
gs.print(str);
with output:
[0:00:00.005] Script completed in scope global: script
*** Script: IN28617860
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 12:38 AM
Hi Juliana,
Try with the following code:
var responseBody = response.getBody();
var xm = new XMLDocument2();
xm.parseXML(responseBody);
var ticketId=xm.getNodeText("//RequesterID");
Thanks & Regards