cancel
Showing results for 
Search instead for 
Did you mean: 

Add XML tag to the XML output File

Former Member
0 Kudos

Experts,

My Scenario is JDBC to File

For the resultant xml file i have to append a line <?Test Line?> after

<?xml version="1.0" encoding="UTF-8" ?> while passing it to legacy system ?

From SDN I found that a XSLT Mapping(as second mapping in the Interface mapping) will do the above requirement,

I got some XSLT Code from SDN to do this

1)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" /> 

  <xsl:template match="/">
 <!--  add processing instruction --> 
  <xsl:processing-instruction
name="POSTEN">SND="SE03220037090" SNDKVAL="1" REC="SE03220669500" MSGTYPE="ORDERS"</xsl:processing-instruction> 
 <!--  copy payload --> 
  <xsl:copy-of select="." /> 
  </xsl:template>
  </xsl:stylesheet>

2)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" /> 
 
 
  <xsl:template match="/">
 <!--  add processing instruction --> 
  <xsl:processing-instruction
name="POSTEN">SND="SE03220037090" SNDKVAL="1" REC="SE03220669500" MSGTYPE="ORDERS"</xsl:processing-instruction> 
 <!--  copy payload --> 
  <xsl:copy-of select="." /> 
  </xsl:template>
  </xsl:stylesheet>

But none of them worked for me, the additional tag does not appear on the o/p xml file

Any help would be appreciated

Srinivas

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I dont see any namespace of the input payload for copying ...

did you added the required namespaces in your code ?

Rajesh

Former Member
0 Kudos

Rajesh

Thanks for your reply

I dont see any namespace of the input payload for copying ...

did you added the required namespaces in your code ?

I copied the same xslt with out any changes.

where i must add my name space of input payload.

Please suggest

Thanks

Srinivas

Answers (5)

Answers (5)

Former Member
0 Kudos

Solved myself, written a unix command in the post processing steps in the receiver file adpater

Former Member
0 Kudos

I had written an XSLT Code to acheive this, i checked in XML spy and it is working.

but in moni it is error in message mapping

my XSLT Code is

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Add the Doctype declaration -->
<xsl:output method="xml" indent="no" doctype-system="http://integratex.quality.techdata.de:8080/ix/dtd/ixOrder.dtd"/>
<!-- Identity Transform - copy the source XML to the output without any changes -->
<xsl:template match="node() | @*">
            <ns0:MT_ASNDATAOUT xmlns:ns0="http://aaaaa/sd/SD152.25">
            <xsl:copy> 
                                                <xsl:apply-templates select="node() | @*"/>
            </xsl:copy>
            </ns0:MT_ASNDATAOUT>
</xsl:template>
</xsl:stylesheet>

and the error in moni is

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <!--  Request Message Mapping 
  --> 
- <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
  <SAP:Category>XIServer</SAP:Category> 
  <SAP:Code area="MAPPING">GENERIC</SAP:Code> 
  <SAP:P1>Parsing error after multi mapping.</SAP:P1> 
  <SAP:P2>Expected Message<i> instead of Messages</SAP:P2> 
  <SAP:P3 /> 
  <SAP:P4 /> 
  <SAP:AdditionalText /> 
  <SAP:ApplicationFaultMessage namespace="" /> 
  <SAP:Stack>Parsing error after multi mapping.Expected Message<i> instead of Messages</SAP:Stack> 
  <SAP:Retry>M</SAP:Retry> 
  </SAP:Error>

In the Message Mapping iam doing doing multi mapping.

Please help me why iam getting an error in moni.

Thanks for your help

Srinivas

shweta_walaskar2
Contributor
0 Kudos

Hello Srinivas,

I had achieved the same using java mapping:

Suppose your XML structure is:

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

<Root Element>----


-


</Root Element>

you can use the following code:

import java.io.*;

import java.util.*;

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

public class AddCommentInXML implements StreamTransformation {

String record=null;

String comment=null;

public void execute(InputStream in, OutputStream out) {

try {

DataInputStream stdin = new DataInputStream(in);

int length = getLengthFromStream(stdin);

stdin.reset();

byte[] buffer = getBytesFromStream(stdin);

String str = new String(buffer);

record = "<Root Element>";

comment ="<!Test Line><Root Element>";

str = str.replaceAll(record,comment);

out.write(str.getBytes());

out.close();

} catch (IOException e) {

}

}

public int getLengthFromStream(InputStream is ) throws

IOException{

int i = 0;

int length = 0;

try{

while ((i = is.read())> 0){

length ++;

}

}catch (ArrayIndexOutOfBoundsException e) {

e.printStackTrace();

}

return length;

}

public byte[] getBytesFromStream(InputStream is) throws

IOException {

// Create the byte array to hold the data

byte[] bytes = new byte[getLengthFromStream(is)];

is.reset();

// Read in the bytes

int offset = 0;

int tmp = 0;

while (offset < bytes.length

&& (is.read(bytes, offset, offset +

(tmp = is.available()))) > 0) {

offset += tmp;

}

// Ensure all the bytes have been read in

if (offset < bytes.length) {

throw new IOException("Could not completely read Inputstream");

}

// Close the input stream and return bytes

is.close();

return bytes;

}

public void setParameter(Map param) {

}

}

Hope this helps.

Regards,

Shweta

Former Member
0 Kudos

I got one more xslt code for the extra tag in the output xml file, But this one also is not working.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- Add the Doctype declaration -->
<xsl:output method="xml" indent="no"
doctype-system="http://integratex.quality.techdata.de:8080/ix/dtd/ixOrder.dtd"/>

<!-- Identity Transform - copy the source XML to the output without any changes -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template> 
</xsl:stylesheet>

Please help me

Srinivas

Former Member
0 Kudos

Hi Experts,

Any Suggestions, Please help me on this.

Srinivas

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Srinivas,

add this statement in your XSLT Mapping

<xsl:text>give your name space here</xsl:text>

Regards,

Raj

Former Member
0 Kudos

Rajesh

Included the names space as you suggested, But still it is not working, Please help me.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" /> 
 
 
  <xsl:template match="/">
 <!--  add processing instruction --> 
  <xsl:processing-instruction
name="POSTEN">SND="SE03220037090" SNDKVAL="1" REC="SE03220669500" MSGTYPE="ORDERS"</xsl:processing-instruction> 
 <!--  copy payload -->
  <xsl:text><a href="http://aaaa.com/sd/SD152.25" TARGET="test_blank">http://aaaa.com/sd/SD152.25</a></xsl:text> 
  <xsl:copy-of select="." /> 
  </xsl:template>
  </xsl:stylesheet>

Srinivas

Former Member
0 Kudos

Any Suggestions,Please help me

Srinivas

rajasekhar_reddy14
Active Contributor
0 Kudos

Try like this.

<NameSpace>

<xsl:text>http://aaaa.com/sd/SD152.25</xsl:text>

</NameSpace>

Former Member
0 Kudos

Paul,

Iam getting an error, PLease suggest

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <!--  Request Message Mapping 
  --> 
- <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
  <SAP:Category>XIServer</SAP:Category> 
  <SAP:Code area="MAPPING" /> 
  <SAP:P1>unexpected symbol: '<'</SAP:P1> 
  <SAP:P2 /> 
  <SAP:P3>1</SAP:P3> 
  <SAP:P4>133</SAP:P4> 
  <SAP:AdditionalText /> 
  <SAP:ApplicationFaultMessage namespace="" /> 
  <SAP:Stack>The exception occurred (program: CL_XMS_MAIN===================CP, include CL_XMS_MAIN===================CM00A, line: 609)</SAP:Stack> 
  <SAP:Retry>M</SAP:Retry> 
  </SAP:Error>

Srinivas