среда, 5 августа 2015 г.

XML to Single Element/XML to String

Could you pls tell me in detail about how to achieve One whole xml into one string element. I am new to all this and have not used xslt or java mapping before.

Answer:

u can use XSLT mapping for inserting the complete input xml file in to string on output.

This is the sample code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<input_tag>
<xsl:text disable-output-escaping="yes"><![CDATA[><![CDATA[]]></xsl:text>
<xsl:copy-of select="output_tag/string_name"/>
<xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>
<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
</input_tag>
</xsl:template>
</xsl:stylesheet>.

or u can use java mapping also
below is the sample code:
//package com.xi.javamapping;
import java.io.DataInputStream;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;

public class XMLToString implements StreamTransformation {
     public void setParameter(Map arg0) {}
     public void execute(InputStream arg0, OutputStream arg1)
          throws StreamTransformationException {
          try {
               DataInputStream dataInputStream = new DataInputStream(arg0);
               StringBuffer sbr = new StringBuffer();
               String str = null;
               while ((str = dataInputStream.readUTF()) != null) {
                    String str1 = str.trim();
                    sbr.append(str1);
                    String string = new String(sbr);
                    byte[] b = string.getBytes();
                    arg1.write(b);
               }
          } catch (IOException e) {
               e.printStackTrace();
          }
     }
      
      
}

Source


 

Комментариев нет:

Отправить комментарий