Skip to Content
0
Former Member
Jul 26, 2013 at 03:55 AM

Remove Doctype from cXML file

462 Views

Hi All,

I need to remove the doctype from incoming cXML file. I read all the forums regarding this issue and decided to use the below link to solve my problem

http://scn.sap.com/thread/3184205

The above link specifies the java code for PI7.1 to remove doctype since I am using PI7.0 I modified the code

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
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.Node;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;

public class DeleteDtd implements StreamTransformation {

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{
DeleteDtd genFormat=new DeleteDtd();
FileInputStream in=new FileInputStream("E:\\input.xml");
FileOutputStream out=new FileOutputStream("E:\\output.xml");
genFormat.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setParameter(Map arg0) {
// TODO Auto-generated method stub

}
}


So when I run this code in eclipse its is removing the doctype but once I deployed in PI 7.0 it is throwing same error as empty document cannot be processed.

Can anyone please let me know what correction I need to make this code to run in PI 7.0 to remove doctype

<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/x.x.xxx/cXML.dtd">