Parse cXML file

1k Views Asked by At

As a response I am getting the below cXML, and its not getting parse if I am using XSLT.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML  SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.046/cXML.dtd">
<cXML payloadID="AF7rzg4Yg6dfzOW5Mfp6PFIAz66C"
      timestamp="2020-06-18T20:26:55+00:00"
      version="1.2.046">
  <Response>
    <Status code="201" text="Acknowledged">Acknowledged</Status>
  </Response>
</cXML>

I am getting below error, can you suggest me how we can parse these kind of files.

Unable to generate the XML document using the provided XML/XSL input. org.xml.sax.SAXParseException; systemId: http://xml.cxml.org/schemas/cXML/1.2.046/cXML.dtd; lineNumber: 1; columnNumber: 1; The markup declarations contained or pointed to by the document type declaration must be well-formed.

My requirement is to get a output XML like

<RESULT>
    <Status>Acknowledged</Status>
</RESULT>

can you let me know the XSLT for that.

enter image description here

Thanks Yatan

2

There are 2 best solutions below

1
Yatan On BEST ANSWER

I was unable to parse this via XSLT, finally used the below expression before using the XSLT to remove it from XML.

convertedData = body.replaceAll("<!DOCTYPE((.|\n|\r)*?)\">", "");
3
Nic Gibson On

If your input document is literally what you have shown above, you'll need to remove all the whitespace before the xml declaration. The can be nothing before the declaration.