on 05-30-2012 10:39 AM
Hi All,
I am working on cXML to IDoc scenario and want to know how to remove !DOCTYPE cXML SYSTEM from the xml because my mapping is throwing an error.
I have searched the solution for this problem but didn't quite find the correct solution.
Actual Message
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd">
<cXML xml:lang="en" payloadID="44108.16188.52343.32310.1@ebs" timestamp="2012-04-26T14:32:23+10:00">
I have tried XSLT and JAVA Mapping but still no luck
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="cXML" />
</xsl:template>
</xsl:stylesheet>
Error
Transformer exception occurred when executing XSLT IA_XSLT_removeDTD/removeDTD(urn:linde.com:xi:A_B2B_XX:CustomerIntegration, -1, 5aa31b80-0835-11dc-af43-f443ac120353)
JAVA
I have got the code from SAP Note: 812966
Error
Application mapping program
DeleteDTDDeclarationWithDOM throws a stream transformation exception: Connection timed out
Can anybody please tell me how to solve this problem.
Thanks
Hi Muhammad,
Please post the complete source XML and the expected target XML. Kindly mention the version of PI you are working in. I think this can be resolved using java mapping.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anupam,
It's quite difficult to paste complete XML because it's huge.
I want output to be as it but without the DOCTYPE
Example
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd">
<cXML xml:lang="en" payloadID="44108.16188.52343.32310.1@abc.com" timestamp="2012-04-26T14:32:23+10:00">
<Header>
<From>
<Credential domain="DUNS">
<Identity>000000000</Identity>
</Credential>
<Credential domain="CompanyName">
<Identity>Ltd</Identity>
</Credential>
<Credential domain="ABN">
<Identity>0000000</Identity>
</Credential>
<Credential domain="ID">
<Identity>000</Identity>
</Credential>
<Credential domain="BranchName">
<Identity>TEST</Identity>
</Credential>
<Credential domain="BranchEmail">
<Identity>test@test.com</Identity>
</Credential>
<Credential domain="MincomAxis">
<Identity>0000000000</Identity>
</Credential>
</From>
</Header>
</cXML>
Output
<?xml version="1.0" encoding="UTF-8"?>
<cXML xml:lang="en" payloadID="44108.16188.52343.32310.1@abc.com" timestamp="2012-04-26T14:32:23+10:00">
<Header>
<From>
<Credential domain="DUNS">
<Identity>000000000</Identity>
</Credential>
<Credential domain="CompanyName">
<Identity>Ltd</Identity>
</Credential>
<Credential domain="ABN">
<Identity>0000000</Identity>
</Credential>
<Credential domain="ID">
<Identity>000</Identity>
</Credential>
<Credential domain="BranchName">
<Identity>TEST</Identity>
</Credential>
<Credential domain="BranchEmail">
<Identity>test@test.com</Identity>
</Credential>
<Credential domain="MincomAxis">
<Identity>0000000000</Identity>
</Credential>
</From>
</Header>
</cXML>
I have tried the JAVA Mapping provided in the SAP note but it is not working in Operation Mapping and I am getting this error.
Error
Application mapping program
DeleteDTDDeclarationWithDOM throws a stream transformation exception: Connection timed out
Hi Iqbal,
>>> It's quite difficult to paste complete XML because it's huge.
>>> DeleteDTDDeclarationWithDOM
>>> Connection timed out
If I add all the information above, the reason seems really simple. Give up using DOM only to remove this <!DOCTYPE> tag. This sounds like using a cannon to kill a fly . Instead, use simple replace function on a string - it will perform MUCH faster and consume much less resources.
Regards,
Greg
Dear Iqbal,
Find a nice example of how to work on input payload as text in Java mapping here:
http://techplay.plozzle.com/?p=21
Most probably changing one line from:
bw.write(line.replaceAll("remove", "delete"));
to:
bw.write(line.replaceAll("<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd">", ""));
should be sufficient to achieve your goal.
Regards,
Greg
Hello Muhammad iqbal,
For XSLT you could use:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
Best regards,
Peter
Hi Greg,
I have tried the JAVA Mapping but still no luck.
Basically the thing is that we can't use 2 "" in replace all
Wrong sentence
bw.write(line.replaceAll("<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd">", ""));
Can you please suggest something else.
Thanks,
Hi Peter,
I have already tried this option but it is not working either.
I am getting this error
Error
Transformer exception occurred when executing XSLTIA_XSLT_removeDTD/removeDTD(urn:linde.com:xi:A_B2B_XX:CustomerIntegration, -1,5aa31b80-0835-11dc-af43-f443ac120353)
Even though I have checked the XML Toolkit option
Thanks,
Iqbal
Hello Iqbal,
bw.write(line.replaceAll("<!DOCTYPE cXML SYSTEM \"http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd\">", ""));
should work I think
I didn't think of it initially, but it's because of the quote appearing inside the whole tag that is meant to be replaced. Try the following line instead, it uses the escape character to avoid special meaning of quotes inside the tag to be replaced:
bw.write(line.replaceAll("<!DOCTYPE cXML SYSTEM \"http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd\">", ""));
Regards,
Greg
Hi Iqbal,
here is the java mapping code for PI 7.1 and above. In case you are working with lower versions thyen code will differ slightly. Since you did not mention the vesrion of PI you are working with I am assuming its 7.1 or above.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
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.Node;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.api.StreamTransformationException;
public class removeDoctype extends AbstractTransformation {
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
try
{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builderel=factory.newDocumentBuilder();
/*input document in form of XML*/
Document docIn=builderel.parse(in);
/*document after parsing*/
Document docOut=builderel.newDocument();
TransformerFactory tf=TransformerFactory.newInstance();
Transformer transform=tf.newTransformer();
Node rootIn,rootOut;
rootIn=docIn.getDocumentElement();
rootOut=docOut.importNode(rootIn,true);
docOut.appendChild(rootOut);
transform.transform(new DOMSource(docOut), new StreamResult(out));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args) {
try{
removeDoctype genFormat=new removeDoctype();
FileInputStream in=new FileInputStream("C:\\apps\\test\\in.xml");
FileOutputStream out=new FileOutputStream("C:\\apps\\test\\out.xml");
genFormat.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
// TODO Auto-generated method stub
this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
}
I have tested this code and it works . Hope this resolves your problem
Regards
Anupam
We had the same problem. The solution we used was to follow the instructions
in http://techplay.plozzle.com/?p=21
To ignore the DOCTYPE statement no matter how the statement is written (mixed case, extra spaces, etc)
replace the line:
bw.write(line.replaceAll("remove", "delete"));
with:
String sub = line;
String find = "<!doctype ";
int ind1 = sub.toLowerCase().indexOf (find.toLowerCase ());
if(ind1 >= 0 )
{
line = "";
}
bw.write(line);
}
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.