cancel
Showing results for 
Search instead for 
Did you mean: 

how to delete DOCTYPE from the message

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

former_member184681
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Greg,

Can you please tell me how?

I don't think so it's that simple otherwise you won't find many discussion on SCN.

I would be really thankful to you if you can please suggest the solution to this problem either UDF, XSLT or JAVA Mapping.

Thanks,

Iqbal

former_member184681
Active Contributor
0 Kudos

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

peter_wallner2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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,




Former Member
0 Kudos

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

peter_wallner2
Active Contributor
0 Kudos

Hello Iqbal,

bw.write(line.replaceAll("<!DOCTYPE cXML SYSTEM \"http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd\">", ""));

should work I think

former_member184681
Active Contributor
0 Kudos

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

former_member184681
Active Contributor
0 Kudos

Agreed, I have also just spotted that

anupam_ghosh2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Thank you so much for all the guys who helped me solving this issue.

I have used Anupam's Code and it is working absoutely fine.

Thank you so much Anupam and Yes I am using PI 7.11 SP6.

I hope other people will find this thread very useful.

Former Member
0 Kudos

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);
}

Answers (0)