Search code examples
javaxmlxpathmulemule-flow

Config <set-variable> with xpath gives empty string while extracting from xml payload


I am working on a service which add the detials sent in the request to to two different queues.

For this I use to extract part of the XML without disturbing the payload. But it is giving blank.

My input looks as below

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://example.org/HelloService">
   <soapenv:Header/>
   <soapenv:Body>
     <AddRequest>
      <Person>
         <firstName>Test</firstName>
         <lastName>Tesst</lastName>
         <age>23</age>
      </Person>
      <Company>
         <companyName>Test</companyName>
         <state>Tesst</state>
         <zip>12345</zip>
      </Company>
     </AddRequest>
   </soapenv:Body>
</soapenv:Envelope>

And part of my flow which is extracting the Person element is as below.

    <set-variable value="#[xpath://Person]" variableName="person"></set-variable>

    <logger level="INFO" message="#[flowVars['person']]" />     
    ........
    ......

But the logger is printing it as blank

2013-01-30 12:56:08,287 INFO  [HelloService.stage1.02] processor.LoggerMessageProcessor (LoggerMessageProcessor.java:108) - 

Any idea why it is extracting blank space instead of the xml element.

How can I get the "Person" element from the paylaod using XPATH?


Solution

  • Try using the XSLT transformer to extract the xml element.

    <xsl:output omit-xml-declaration="yes" indent="yes" />
    
    <xsl:template match="/">
        <xsl:copy copy-namespaces="no">
            <xsl:apply-templates select="//Person" />                   
        </xsl:copy>     
    </xsl:template>
    
    <xsl:template match="@*|node()">
        <xsl:copy copy-namespaces="no">
            <xsl:apply-templates select="@*|node()" />                  
        </xsl:copy>     
    </xsl:template>