Transform String into xml object for Request

Rodolfo

I need integrate with a system with this WSDL: wsdl

In Studio, I use "Web Service Consumer". The problem is in the body. IN transform I create the payload, but i only get it to work if i hardcode it; I can't make the string dynamic

This script works but it uses fixed literal strings:

%dw 2.0
output application/xml
ns ns0 http://test.es/IC/SERVICE/
---
{
    ns0#wsImprXML: {
        ns0#DataXML: "
                    <root>
                        <exp>
                            <bult>
                                <ci>965</ci> 
                                <nif>123</nif> 
                                <ccc>36020</ccc>
                                <service>31</service> 
                                <product>2</product> 
                                <total>1</total> 
                                <price>10,6</price> 
                            </bult>
                        </exp>
                    </root>",
        ns0#OptionsXML: "<wsOptionsXML>
                                <VersionDataXML>1.0.0</VersionDataXML>
                                <VersionOptionsXML>1.0.0</VersionOptionsXML>
                                <VersionResponseXML>1.1.0</VersionResponseXML>
                                <VersionErrorXML>3.2.0</VersionErrorXML> 
                            </wsOptionsXML>"
    }
}

How can I create the string inside the body of the xml? This string must be dynamic (filling it with values ​​that I have stored in variables)?

aled

You should not use literal XML. You can easily generate XML dynamically from anything that DataWeave considers an object. I'll give an example with DataWeave variables, that you can replace by Mule variables (vars.myVar). Using the write() function converts an object into a string as your WSDL requires. You can pass the transformed text, or convert it in place, as I'm showing below.

%dw 2.0
output application/xml
ns ns0 http://test.es/IC/SERVICE/
var someText=write(
    {
        root: {
            exp: {
                bult: {
                    ci: 965,
                    nif: 123,
                    ccc: 36020,
                    service: 31,
                    product: 2,
                    total: 1,
                    price: 10.6
                }
            }
        }
    }, "application/xml")
            
 
var someObject= {
        wsOptionsXML: {
            VersionDataXML: "1.0.0",
            VersionOptionsXML: "1.0.0",
            VersionResponseXML: "1.1.0",
            VersionErrorXML:"1.2.0"
        }
    }                    
---
{
    ns0#wsImprXML: {
        ns0#DataXML: someText,
        ns0#OptionsXML: write(someObject,"application/xml")
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Convert Java object to XML string

How to 'transform' a String object (containing XML) to an element on an existing JSP page

How do you debug an xml object that causes a transform error when writing to string?

How do I transform a List<String[]> to an XML Object using XMLMapper (Jackson)?

Convert XML String to Object

Transform string to object in Javascript

How to Transform string message error in object or array?

How to transform string into object by Lodash

String manipulations for javax.xml.transform.Source

Transform XML into string JAVA

How to transform a series object into a single string

How to transform XML text received through an AJAX request into a file

Trying to transform this string to an object

How to transform an xml structure generated from a request to a web services

Javascript transform xml to json object and save into javascript var

how to to transform an object to a string php

Parse and transform XML string in JavaScript

How to transform java object to XML with axis 1.4?

Transform XML to HTML in XSLT with string length condition

Transform bad string format object into real object in JavaScript

How to transform a String containing XML tags into a XML document

Transform XML "yes/no" string to boolean

Convert Xml request to Object Spring Boot

XML string or object serialization?

Transform request object to array for database insert

how to transform a string object into an array in ruby on rails?

F# execute XSL Transform from XML String and returns string

Transform object into a string with required pattern: Javascript

Transform `Request` headers to plain key value object