xml to xml transformation in mule

7

Click here to load reader

Upload: domenico-schiavone

Post on 13-Apr-2017

46 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Xml to xml transformation in mule

TRANSFORMATION BETWEEN TWO XML WITH MULE

Page 2: Xml to xml transformation in mule

There are multiple types of payload that we need to deal daily, starting from JSON,  XML or String.

It is possible to require different type of data transformation in our application for example JSON to XML or String, XML to JSON etc .

With a Mule application, we have a set of transformers that we can use to obtain our required data format.

Page 3: Xml to xml transformation in mule

<RootTag> <name>Sebastian Ritch</name> <id>60</id></RootTag>The XML contains two elements, that is name and id.

We have the following XML payload as an input

Page 4: Xml to xml transformation in mule

The challenge is to modify the existing input XML payload and to design an output XML payload from it, which will contain an additional element in it with the same format.IE.<RootTag><name>Sebastian Ritch</name><id>60</id><designation>Manager</designation></RootTag>

Page 5: Xml to xml transformation in mule

Now we use the XSLT in Mule. <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"

xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/

beanshttp://www.springframework.org/schema/beans/spring-beans-

current.xsdhttp://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsdhttp://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsdhttp://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd"> <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>

Page 6: Xml to xml transformation in mule

<flow name="transformationxmltoxmlFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/xmltest" doc:name="HTTP"/> <set-variable variableName="designation" value="Manager" doc:name="Variable"/> <mulexml:xslt-transformer xsl-file=«E:\Exercise\xmlTransformation.xsl" maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT" mimeType="application/xml"> <mulexml:context-property key="designation" value="#[flowVars.designation]"/> </mulexml:xslt-transformer> <logger level="INFO" message="Output: #['\n' + message.payload]" doc:name="Logger"/> </flow></mule>

Page 7: Xml to xml transformation in mule