- 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 04:07 PM
Hi Juliana,
I tried below code and it works for me as well. Be careful to encode the double quote in 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 XMLDocument(xmlString);
var str = xmldoc.getNodeText("//RequesterID");
gs.print(str);
==================================
Cheers
Henry