on 10-23-2009 4:58 PM
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
Hi,
I dont see any namespace of the input payload for copying ...
did you added the required namespaces in your code ?
Rajesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Solved myself, written a unix command in the post processing steps in the receiver file adpater
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Experts,
Any Suggestions, Please help me on this.
Srinivas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Srinivas,
add this statement in your XSLT Mapping
<xsl:text>give your name space here</xsl:text>
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
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.