I needed to jump head first into escaping/unescaping xml and Xpath to work with a web service that we have recently subscribed to. I've never used xpath before, although it seems pretty straightforward.
I was able to get a working example of my code using the debugger:
var request = [ '<?xml version="1.0" encoding="utf-8"?>', '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' + ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">', '<soap:Body>', '<GetProvider xmlns="http://tempuri.org/">', '<first />', '<last>paskil</last>', '<state>CA</state>', '<zip />', '<uid>xxxxxxx</uid>', '<pwd>xxxxxxx</pwd>', '</GetProvider>', '</soap:Body>', '</soap:Envelope>' ]; var url = 'xxxx/xxxxxx/xxxxxxxx/xxxxxxx.asmx'; var a = new Array(); a['Content-Type'] = 'text/xml; charset=utf-8'; var response = nlapiRequestURL( url, request.join(''), a); var body = response.getBody(); body = unescapeXml(body); var xmlDoc = nlapiStringToXML(body); var topResponse = nlapiSelectNode(xmlDoc, '//GetProviderResponse'); var response = nlapiSelectNode(topResponse, '//GetProviderResult/NPISearchResponse'); function unescapeXml(escapedXml) { var unescaped = escapedXml.replace(/>/g, '>'); unescaped = unescaped.replace(/</g, '<'); return unescaped; } This works fine in the debugger! Very happy, xPath is cool and I learned a lot - all good stuff...So then it comes to actually using the above lessons...I have a client script that will call the service and render the results in a SuiteLet. The first nlapiSelectNode() returns null.SAME code that I used in the debugger... same EXACT code yet very different results.So.... I understand the debugger is running on the server end (most likely on Oracle's app server J2ee deal-bob) and on the client...well, it's the client. Shouldn't these still work the same?Anyone have any clues for me?Here is the XML pre-"unescape" (which, BTW, I have no idea if I'm doing correctly):<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetProviderResponse xmlns="http://tempuri.org/"><GetProviderResult><NPISearchResponse><IsSuccess>True</IsSuccess><ErrorMessage></ErrorMessage><ProviderDetails><ProviderDetail><NPI>1942228697</NPI><ProviderName>Paskil,David</ProviderName><Street>14150 Culver Drive</Street><City>Irvine</City><State>CA</State><Zip>92604</Zip><Phone>9495524584</Phone><Fax>9495515612</Fax><PrimaryTaxonomy>Allopathic & Osteopathic Physicians</PrimaryTaxonomy></ProviderDetail><ProviderDetail><NPI>1629012372</NPI><ProviderName>Paskil,Jeffrey</ProviderName><Street>3033 W Orange Ave</Street><City>Anaheim</City><State>CA</State><Zip>92804</Zip><Phone>3104403131</Phone><Fax>3104729582</Fax><PrimaryTaxonomy>Allopathic & Osteopathic Physicians</PrimaryTaxonomy></ProviderDetail></ProviderDetails></NPISearchResponse></GetProviderResult></GetProviderResponse></soap:Body></soap:Envelope>
Ant he unescapted xml:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetProviderResponse xmlns="http://tempuri.org/"><GetProviderResult><NPISearchResponse><IsSuccess>True</IsSuccess><ErrorMessage></ErrorMessage><ProviderDetails><ProviderDetail><NPI>1942228697</NPI><ProviderName>Paskil,David</ProviderName><Street>14150 Culver Drive</Street><City>Irvine</City><State>CA</State><Zip>92604</Zip><Phone>9495524584</Phone><Fax>9495515612</Fax><PrimaryTaxonomy>Allopathic & Osteopathic Physicians</PrimaryTaxonomy></ProviderDetail><ProviderDetail><NPI>1629012372</NPI><ProviderName>Paskil,Jeffrey</ProviderName><Street>3033 W Orange Ave</Street><City>Anaheim</City><State>CA</State><Zip>92804</Zip><Phone>3104403131</Phone><Fax>3104729582</Fax><PrimaryTaxonomy>Allopathic & Osteopathic Physicians</PrimaryTaxonomy></ProviderDetail></ProviderDetails></NPISearchResponse></GetProviderResult></GetProviderResponse></soap:Body></soap:Envelope>