Frage

In Netsuite Script I am trying to parse the response from EchoSign Webservice. The response from EchoSign is like this

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <getFormDataResponse xmlns="http://api.echosign">
            <getFormDataResult xmlns="http://api.echosign">
                <errorCode xmlns="http://dto8.api.echosign">OK</errorCode>
                <errorMessage xmlns="http://dto8.api.echosign" xsi:nil="true" />
                <formDataCsv xmlns="http://dto8.api.echosign">SOME DATA </formDataCsv>
                <success xmlns="http://dto8.api.echosign">true</success>
            </getFormDataResult>
        </getFormDataResponse>
    </soap:Body>
</soap:Envelope>

And my NetSuite code is here

var response = nlapiRequestURL(echoSignUrl, postStr, header);
    var xml = nlapiStringToXML(response.getBody());

    var resData = nlapiSelectNode(xml, 'soap:Envelope/soap:Body'); // /getFormDataResult/success');
    if (resData)
        return nlapiSelectValue(resData, 'formDataCsv');

But somehow I always get nothing back from nlapiSelectValue method!!

War es hilfreich?

Lösung

Nodes without any prefix should be accessed using default prefix nlapi:

for e.g. /soap:Envelope/soap:Body/nlapi:getFormDataResponse

Andere Tipps

It appears to be an issue with the way the namespacing is handled. Using the XML Tools plugin for Notepad++ and the XML you've provided, the XPATH Current Node Selector can't even find the getFormDataResponse node correctly. It simply fails with "Unknown Exception".

I also tried to manually evaluate the following expressions:

  • /soap:Envelope/soap:Body (works)
  • /soap:Envelope/soap:Body/getFormDataResponse (fails)
  • /soap:Envelope/soap:Body//getFormDataResponse (fails)
  • /soap:Envelope/soap:Body/*[local-name() = 'getFormDataResponse'] (fails)
  • /soap:Envelope/soap:Body/descendants::*[local-name() = 'getFormDataResponse'] (fails)
  • /soap:Envelope/soap:Body/descendants::getFormDataResponse (fails)

If I modify the XML so the EchoSign namespaces are in the Envelope with a prefix, like so:

<soap:Envelope xmlns:echo="http://api.echosign" xmlns:dto8="http://dto8.api.echosign" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <echo:getFormDataResponse>
            <echo:getFormDataResult>
                <dto8:errorCode>OK</dto8:errorCode>
                <dto8:errorMessage xsi:nil="true" />
                <dto8:formDataCsv>SOME DATA</dto8:formDataCsv>
                <dto8:success>true</dto8:success>
            </echo:getFormDataResult>
        </echo:getFormDataResponse>
    </soap:Body>
</soap:Envelope>

then the path selector can get all the way down to the formDataCsv node correctly. It returns the path: /soap:Envelope/soap:Body/echo:getFormDataResponse/echo:getFormDataResult/dto8:formDataCsv. Not sure how helpful that is because you're not in control of the XML that EchoSign sends to you, but I'm not sure how to correctly format the XPATH to deal with the namespaces.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top