Juanfra Magrini
Juanfra Magrini

Reputation: 31

Get value from SOAP Message using Xpath on Mule

I want to get the value of arg0. This is my code

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sup="http://support.cxf.module.mule.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <sup:invoke name="INVOKE">
         <!--Optional:-->
         <sup:arg0 name="ARG0">pichon</sup:arg0>
      </sup:invoke>
   </soapenv:Body>
</soapenv:Envelope>

And this is how I'm trying to get the value:

<logger message="#[xpath3('/*/soapenv:Envelope/soapenv:Body/sup:invoke/sup:arg0',payload, 'NODESET')]" level="INFO" doc:name="Logger"/>

Before that I declared these namespaces:

<mulexml:namespace-manager includeConfigNamespaces="true">
  <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/>
 <mulexml:namespace prefix="sup" uri="http://support.cxf.module.mule.org/"/>
</mulexml:namespace-manager>

But I can't, I'm getting this error:

Caused by: org.mule.api.MessagingException: Execution of the expression "xpath3('/*/soapenv:Envelope/soapenv:Body/sup:invoke/sup:arg0',payload, 'NODESET')" failed. (org.mule.api.expression.ExpressionRuntimeException).

I'm using mule 3.8 and anypoint studio 6.1.2 I would appreciate if someone could help me! Thanks!

Upvotes: 1

Views: 842

Answers (1)

Juanfra Magrini
Juanfra Magrini

Reputation: 31

Finally, I found a solution about getting the value of arg0.

I had to declare a dom-to-xml-transformer before call xpath3. Also, I declared the namespace with prefix="sup" in order to use in the query in xpath3.

Here is the code:

// declared before the flow
<mulexml:namespace-manager includeConfigNamespaces="true">     
 <mulexml:namespace prefix="sup" uri="http://support.cxf.module.mule.org/"/>
</mulexml:namespace-manager>

// into the flow
<mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
<logger  message="#[xpath3('/sup:invoke/sup:arg0',payload, 'STRING')]"  level="INFO" doc:name="Logger"/>

Regards,

Juanfra.

Upvotes: 1

Related Questions