on 03-22-2011 2:45 PM
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
Hi Amith,
Thanks for the mapping will try it and let you know soon.
Thanks
rajesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can anyone provide the javamapping that can be used ? .Please provide the mapping .
Thanks
Rajesh Naidu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can do this by using an UDF function (catching xml data needed), or using a Java Mapping.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can remove the nodes responsepayload and respstring using a simple java mapping and pass the data as is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.