Hi,
Maybe I am mad but I cannot fathom why this does not work.
My Response body:
<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> <ns1:createLineOwnerResponse xmlns:ns1="http://imperatives.co.uk/V20"> <ns1:CreateLineOwnerResponse> <messages xmlns="http://model.inventory.empower.vnocore.com"> <ns2:EmpowerMessage xmlns:ns2="http://model.common.empower.vnocore.com"> <completionCode xmlns="http://model.common.empower.vnocore.com">SII002</completionCode> <message xmlns="http://model.common.empower.vnocore.com">Line Owner Already Exists</message> <severity xmlns="http://model.common.empower.vnocore.com">ERROR</severity> </ns2:EmpowerMessage> </messages> </ns1:CreateLineOwnerResponse> </ns1:createLineOwnerResponse> </soap:Body> </soap:Envelope>
Returned by script: var stResponseCode = wsResponse.getCode(); var stSoapBody = wsResponse.getBody(); var xmlSoap = nlapiStringToXML(stSoapBody); // Create Form var form = nlapiCreateForm('Approval of Purchase Order Lines'); var fld = form.addField('custpage_stage','longtext','request').setDisplaySize(200, 500) var XMLEmpowerMessage = nlapiSelectNode(xmlSoap, "//*[name()='ns2:EmpowerMessage']" ); var stXMLEmpowerMessage1 = nlapiSelectValue(XMLEmpowerMessage,"//*[name()='completionCode']"); fld.setDefaultValue(stXMLEmpowerMessage1) response.writePage(form); My question is how do I correctly use XPath with the nlapiSelectNode, nlapiSelectValue?My understanding (which may be completely incorrect) is that I should be able to select a node of xml using nlapiSelectNode, then select an inner node using nlapiSelectNode and then return the value of a particular contained node using nlapiSelectValue. Is this correct?Like return:messages <--- first nlapiSelectNode<ns2:EmpowerMessage xmlns:ns2="http://model.common.empower.vnocore.com"> <--- second nlapiSelectNode after passing first nlapiSelectNode resultSII002 <-- return from nlapiSelectNodeValue passing second nlapiSelectNode and XPath "/completionCode"An example code (using responce above): var xmlContainerNode= nlapiSelectNode(xmlSoap, "//*[name()=ns1:CreateLineOwnerResponse]" ); var xmlInnerNode= nlapiSelectValue(xmlContainerNode, "//*[name()='ns2:EmpowerMessage']" ); var xmlNodeValue= nlapiSelectNode(xmlInnerNode,"//*[name()='completionCode']");
Related questions are:Why can I seem not be able to use other XPath to traverse XML without error. for example: var XMLEmpowerMessage = nlapiSelectNode(xmlSoap, "//ns2:EmpowerMessage" ); var stXMLEmpowerMessage1 = nlapiSelectValue(XMLEmpowerMessage,"/completionCode");
Any help would be much appreciated!- Tristan