0
votes

I am facing one issue while xml format conversion in mule transform message.

I am having one input xml file.

and I have to convert the input xml to output xml where the node structure is different and node names are different. I used data transform message for this conversion, But at one point, it is showing expected format is object and found string. Can any one please help me for the same.

"Type mismatch found :name, :string required :name, :object (com.mulesoft.weave.mule.exception.WeaveExecutionException). Message payload is of type: WeaveMessageProcessor$WeaveOutputHandler"

input payload 
<?xml version="1.0" encoding="utf-8"?>
 <AGREEMENT>
  <details>
  <newTransaction>N</newTransaction> 
   <type>ddd</type> 
   </details>
 </AGREEMENT>

output Payload

 <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:xsd="http://www.w3.org/2001/XMLSchema"     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<TestHeader xmlns="TestWebService">
    <Username>aaa</Username>
    <Password>aaa</Password>
</TestHeader>
 </soap:Header>
    <soap:Body>
        <AGRMNT>
        <testId>
        <_-Test_Agrmnt- SEGMENT="1">
            <transaction>N</transaction>
        </__-Test_Agrmnt->
    </testId>
  </AGRMNT>
 </soap:Body>
</soap:Envelope>

DataWeave code

%dw 1.0
%output application/xml
 %namespace soap http://schemas.xmlsoap.org/soap/envelope/

{
 soap#Envelope: {
    soap#Body: {

        AGREEMENT: {

            testId: {
            '_-Test_Agrmnt-': {

                    transaction: payload.AGREEMENT.details.newTransaction as   :string
                    }
                }
            }
        }}
1
can you provide your xml input and output?Arden Vallente
Your output file is not well formatted. please post expected outputAnupamBhusari

1 Answers

0
votes

I have got following output with your input and script

<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AGREEMENT>
      <testId>
         <_-Test_Agrmnt->
           <transaction>N</transaction>
         </_-Test_Agrmnt->
     </testId>
   </AGREEMENT>
 </soap:Body>
</soap:Envelope>

The only change is adding --- in script

<dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
                %output application/xml
                %namespace soap http://schemas.xmlsoap.org/soap/envelope/
                ---
                {
                 soap#Envelope: {
                    soap#Body: {

                        AGREEMENT: {

                            testId: {
                            '_-Test_Agrmnt-': {

                                    transaction: payload.AGREEMENT.details.newTransaction as :string
                                    }
                                }
                            }
                        }}}]]>
        </dw:set-payload>
        </dw:transform-message>