Hi,
I am attempting to call a webservice from a suitelet within netsuite to return back a list of addresses. I have got as far as getting the SOAP response which is as follows
<?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> <GetAvailableAddressesResponse xmlns="https://webservices.opalonline.co.uk/AddressMatchingService"> <GetAvailableAddressesResult>Success</GetAvailableAddressesResult> <AddressResults> <Address> <SubBuilding>Unit G9</SubBuilding> <BuildingName>Genesis Centre</BuildingName> <Street>Garret Field</Street> <Locality>Birchwood</Locality> <PostTown>Warrington</PostTown> <PostCode>WA3 7BH</PostCode> <ALK>A00030924125</ALK> <CSSDistrictCode>LV</CSSDistrictCode> <Qualifier>Gold</Qualifier> </Address> <Address> <BuildingName>Y7 Genesis Centre</BuildingName> <Street>Garrett Field</Street> <Locality>Birchwood</Locality> <PostTown>Warrington</PostTown> <County>Cheshire</County> <PostCode>WA3 7BH</PostCode> <Qualifier>Silver</Qualifier> </Address> <Address> <OrganisationName>CAMPAIGN FOR LEARNING</OrganisationName> <BuildingName>Genesis Centre</BuildingName> <Street>Garrett Field</Street> <Locality>Birchwood</Locality> <PostTown>Warrington</PostTown> <County>Cheshire</County> <PostCode>WA3 7BH</PostCode> <Qualifier>Silver</Qualifier> </Address> </AddressResults> </GetAvailableAddressesResponse> </soap:Body> </soap:Envelope>
As you can see there can be multiple addreses returned (which need to be displayed to the user) and addresses can have a different format (i.e. some have an "OrganisationName" node, others dont. Some have a "SubBuilding" node, others dont).I have tried multiple different ways of getting hold of this data however the xpath queries i am using (new comer to xpath) dont always seem to be working as expected (as i have seen in examples outside of Netsuite)for example take the follow code: - //send the SOAP request webresponse = nlapiRequestURL(xmlData[0],xmlData[1],soapHeaders); //get SOAP response responseCode = webresponse.getCode(); soapXML = nlapiStringToXML(soapText); responseInfo = nlapiSelectNode(soapXML, "//soap:Envelope/*");
The responseInfo variable would contain "[soap:Body:null]". Whilst im not sure about the null i can see that this statement is returning what it should (i.e. the child nodes of soap:Envelope). If i were to swap this line of code for the following (as suggested in the Netsuite strikeiron example): - responseInfo = nlapiSelectNode(soapXML, "//*[name()='soap:Envelope']");
i get the same result, which is good news. However take the following two alternatives: - responseInfo = nlapiSelectNode( soapXML, "//soap:Envelope/soap:Body/GetAvailableAddressesResponse/*"); responseInfo = nlapiSelectNode( soapXML, "//*[name()='GetAvailableAddressesResult']");
I would expect the result from these two different lines of code to be the same (i.e. the responseInfo variable to contain ""[GetAvailableAddressesResult:null]"). The second line of code does return this result but the first just returns nothing, not even null! This is very confusing and i dont know why it is?In another situation i could use the "//*[name() = ' NodeIWant'] syntax, however because i am getting multiple nodes with the same name and this syntax does not care where the node is within the document i will not be able to find the information i require.Does anyone have any suggestions on how i can do this? does anyone have any examples?many thanksDavid