Search code examples
wso2wso2-esbwso2-data-services-serverwso2-micro-integrator

How to remove <?xml version='1.0' encoding='UTF-8'?> tag from the dss output in WSO2 MI


I have to iterate the DB result.

I used dss to fetch the data from the DB. Now results are coming in a xml format. But my flow is not entering into the iterate mediator. I tried with xpath online tool after removing the xml tag from the output able to form the expression.

Is really required to remove the tag <?xml version='1.0' encoding='UTF-8'?> from the output?

If yes, how to remove this?

I am using WSO2 MI 4.1.0

Below are the sample output from my DB call,

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <Entries xmlns="TotscoDS">
      <statusCodePresent>429
      </statusCodePresent>
      <statusCodePresent>429
      </statusCodePresent>
      <statusCodePresent>429
      </statusCodePresent>
      <statusCodePresent>429
      </statusCodePresent>
      <statusCodePresent>429
      </statusCodePresent>
    </Entries>
  </soapenv:Body>
</soapenv:Envelope>
<payloadFactory media-type="xml">
<format>
<getStates>
<msID>$1</msID>
</getStates>
</format>
<args>
<arg evaluator="xml" expression="$ctx:MI_ID"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<header name="Action" scope="default" value="retrieveStateDetails"/>
<call>
<endpoint key="TotscoEP" />
</call>
<log level="full" />
<iterate expression="//Entries" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<target>
<sequence>
<property expression="//statusCodePresent/text()" name="statusCodePresent" scope="default" type="STRING"/>  
<log level="custom">
<property expression="fn:concat($ctx:HUBMessageID,' : StatusCode = ',$ctx:statusCodePresent)" name="Message"/>
</log>
<filter regex="false" source="boolean(get-property('statusCodePresent'))">
<then>
<log level="custom">
<property expression="fn:concat($ctx:HUBMessageID,' : No Status Code from RCP')" name="Message"/>
</log>

</then>
<else/>                                                                 
</filter>
</sequence>
</target>
</iterate>
[Response in log](https://i.sstatic.net/XIohISqc.png)

Solution

  • Your namepsace and the Xpath is the issue. Change the Iterate expression like below.

    <iterate expression="//dss:statusCodePresent" xmlns:dss="TotscoDS">
      <target>
        <sequence>
    .
    .
    .
        </sequence>
      </target>
    </iterate>