0

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

Yatan
  • 89
  • 5

2 Answers2

0

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.

Nic Gibson
  • 7,051
  • 4
  • 31
  • 40
  • The XML has no whitespaces, I have edited my xml to avoid confusion. – Yatan Jun 19 '20 at 16:22
  • Not sure what your problem is then - SAX is saying that your first character is invalid. If I copy that XML into a parser it's both well-formed and valid. – Nic Gibson Jun 19 '20 at 17:51
  • When I try to use XSLT to parse this XML I am getting error. my requirement is to get the output xml like Acknowledged – Yatan Jun 26 '20 at 19:32
0

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)*?)\">", "");
Yatan
  • 89
  • 5
  • This isn't really a solution. If that works it suggests that you might now have your SAX parser configured correctly as it's not loading the DTD at a guess. – Nic Gibson Jun 29 '20 at 16:41