How you parse a SOAP response depends on how you called the service:
- Web service integration (WSDL imported): you never see the envelope - BPM maps the response body to the generated business objects; tw.local.response.customer.name is ready to use. Faults arrive as errors (catch with an error boundary).
- Raw SOAP text (Java HTTP client, a REST call to a SOAP endpoint, a message from a queue): parse the XML in a script. On BPM 8.x the server-side JavaScript supports E4X (XML literals) - the quickest way; on BAW 20+ E4X is gone and you use the Java DOM / XPath from the script:
// BPM 8.5.x / 8.6 - E4X (server-side script)
var xml = new XML(tw.local.soapText.replace(/^<\?xml[^>]*\?>/, "")); // strip the XML declaration
var soap = new Namespace("http://schemas.xmlsoap.org/soap/envelope/");
var ns = new Namespace("http://example.com/customer");
var body = xml.soap::Body;
tw.local.name = String(body.ns::getCustomerResponse.ns::customer.ns::name);
tw.local.limit = parseFloat(body.ns::getCustomerResponse.ns::customer.ns::creditLimit);
// BAW 20+ / any version - Java XPath (no E4X)
var dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);
var doc = dbf.newDocumentBuilder().parse(new org.xml.sax.InputSource(new java.io.StringReader(tw.local.soapText)));
var xp = javax.xml.xpath.XPathFactory.newInstance().newXPath();
tw.local.name = String(xp.evaluate("//*[local-name()='customer']/*[local-name()='name']/text()", doc));
tw.local.limit = parseFloat(xp.evaluate("//*[local-name()='creditLimit']/text()", doc));
var fault = String(xp.evaluate("//*[local-name()='Fault']/*[local-name()='faultstring']/text()", doc));
if (fault) throw new Error("SOAP fault: " + fault);Tips: use local-name() in XPath to ignore namespace prefixes; convert Java strings with String(...) before storing in tw.local; for large responses map only the fields you need; when the same parsing is needed in several places, put it into a toolkit service with the SOAP text in and a business object out. For 8.5.x code that must survive the BAW upgrade, write the XPath version now - E4X removal is one of the classic upgrade breakers.
References