cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping an XML from an input element to Target

Former Member
0 Kudos

Hi ,

I have an XML coming in source Element as below :

<?xml version="1.0" encoding="UTF-8"?>

<ResponsePayload>

<RespString><?xml version="1.0" encoding="UTF-8"?>

<Devices>

<Device>1</Device>

<Name>1</Name>

</Devices></RespString>

</ResponsePayload>

and I need to map it to the target where the target structure is as below .

<?xml version="1.0" encoding="UTF-8"?>

<Devices>

<Device/>

<Name/>

</Devices>

The entire target xml is coming in a source field and that needs to be mapped.

How to perform this?Can any one suggest the methods to do this ?

Thanks

Rajesh

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Amith,

Thanks for the mapping will try it and let you know soon.

Thanks

rajesh

Former Member
0 Kudos

Add the libraries and Tweak as needed.. here's the gist.

public class GetResponse extends AbstractTransformation {

public void transform(TransformationInput arg0, TransformationOutput arg1)

throws StreamTransformationException {

String inputPayload = convertInputStreamToString(arg0.getInputPayload()

.getInputStream());

String inputPayload = convertInputStreamToString(arg0.getInputPayload()

.getInputStream());

String outputPayload = "";

inputPayload = inputPayload.replaceAll("<ResponsePayload>", "");

inputPayload = inputPayload.replaceAll("</ResponsePayload>", "");

inputPayload = inputPayload.replaceAll("<RespString>", "");

inputPayload = inputPayload.replaceAll("</RespString>", "");

inputPayload = start + inputPayload + end;

outputPayload = inputPayload;

try {

arg1.getOutputPayload().getOutputStream().write(

outputPayload.getBytes("UTF-8"));

} catch (Exception exception1) {

}

}

public String convertInputStreamToString(InputStream in) {

StringBuffer sb = new StringBuffer();

try {

InputStreamReader isr = new InputStreamReader(in);

Reader reader = new BufferedReader(isr);

int ch;

while ((ch = in.read()) > -1) {

sb.append((char) ch);

}

reader.close();

} catch (Exception exception) {

}

return sb.toString();

}

}

Mind you the code would change if there's and empty node.

Similarly you would also need to remove an extra version and encoding tag which you get from source.

Edited by: AMITH GOPALAKRISHNAN on Mar 22, 2011 4:57 PM

Former Member
0 Kudos

can anyone provide the javamapping that can be used ? .Please provide the mapping .

Thanks

Rajesh Naidu

Former Member
0 Kudos

You can do this by using an UDF function (catching xml data needed), or using a Java Mapping.

Former Member
0 Kudos

You can remove the nodes responsepayload and respstring using a simple java mapping and pass the data as is.