cancel
Showing results for 
Search instead for 
Did you mean: 

xml to string

Former Member
0 Kudos

I have use the same code of Michael

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

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:p2="urn:DSPConnections:BPPublish">

<xsl:strip-space elements="*"/>

<xsl:template match="/">

<p2:dspXMLRequest xmlns:p2="urn:com.massmutual.schemas:enttechservice:dsp">

<applicationXMLString>

<xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>

<xsl:copy-of select="p2:msgT_R3_BPPub_WM/ZBP"/>

<xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>

<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>

</applicationXMLString>

</p2:dspXMLRequest>

</xsl:template>

</xsl:transform>

Unfortunately iam not getting data at target side

My target looks like this after execution

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

- <p2:dspXMLRequest xmlns:p2="urn:com.massmutual.schemas:enttechservice:dsp">

- <applicationXMLString>

- <![CDATA[

]]>

</applicationXMLString>

</p2:dspXMLRequest>

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Check with the CDATA usage something is incorrect. Are the XML tags coming properly?

Thanks

Gaurav

Former Member
0 Kudos

I have tried creating two simple message types

Request with 4 level deep structure and Response with single field.

For this XSLT mapping (Michael's code ) is working good.

Not sure why it is not working for my real interface.

Former Member
0 Kudos

Hi

Check for the attributes, Source and target namespaces should be same.. If attributes are not getting passed to target then there is a modification required to code.

Thanks

Gaurav

Edited by: Gaurav Bhargava on Oct 26, 2008 2:53 AM

Former Member
0 Kudos

Thanks to Santosh for giving Java code..

Thanks to Gaurav,, to poin that source and target name spaces.

When I change the name spaces of target same to source urn, it did the the desired result.

Keep contributing...

Answers (2)

Answers (2)

Former Member
0 Kudos

I wanted to know how to convert a string into an xml soap message output.

santhosh_kumarv
Active Contributor
0 Kudos

Hi Viswanth,

Try if my wiki works for you....

[Java Mapping- Convert the Input xml to String |https://wiki.sdn.sap.com/wiki/display/XI/JavaMapping-ConverttheInputxmlto+String]

Thanks

SaNv...

Former Member
0 Kudos

Hi Santosh,

Even you code is not giving me the desired results.

This is the code

/*

  • Created on Oct 22, 2008

*

  • To change the template for this generated file go to

  • Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments

*/

package com.mm.bi.sybase;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.util.Map;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Text;

import com.sap.aii.mapping.api.MappingTrace;

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

import com.sap.aii.mapping.api.StreamTransformationConstants;

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

/**

*

  • To change the template for this generated type comment go to

  • Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments

*/

public class SybaseConnect implements StreamTransformation {

/**

*/

public SybaseConnect() {

super();

// TODO Auto-generated constructor stub

}

public void setParameter(Map param) {

Map map = param;

}

public void execute(InputStream in, OutputStream out)

throws com.sap.aii.mapping.api.StreamTransformationException {

try {

//***********************Code To Generate The XML Parsing Objects****************************//

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();

TransformerFactory tf = TransformerFactory.newInstance();

Transformer transform = tf.newTransformer();

Document doc = db.parse(in);

Document docout = db.newDocument();

Element root = docout.createElement("dspXMLRequest");

root.setAttribute("xmlns:ns","urn:com.mass.schemas:enttechservice:dsp");

docout.appendChild(root);

Element stringinp = docout.createElement("applicationXMLString");

root.appendChild(stringinp);

BufferedReader inpxml = new BufferedReader(new InputStreamReader(in));

StringBuffer buffer = new StringBuffer();

String line="";

while ((line = inpxml.readLine()) != null)

{

buffer.append(line);

}

String inptxml=buffer.toString();

Text srcxml = docout.createTextNode(inptxml);

stringinp.appendChild(srcxml);

DOMSource domS = new DOMSource(docout);

transform.transform((domS), new StreamResult(out));

} catch (Exception e) {

System.out.print("Problem parsing the file: " + e.getMessage());

e.printStackTrace();

}

}

}

SAME RESULT::

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

<dspXMLRequest xmlns:ns="urn:com.mass.schemas:enttechservice:dsp">

<applicationXMLString/>

</dspXMLRequest>

Edited by: Viswanath on Oct 24, 2008 9:04 PM