Yatan
Yatan

Reputation: 93

Parse cXML file

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

Upvotes: 0

Views: 1314

Answers (2)

Yatan
Yatan

Reputation: 93

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)*?)\">", "");

Upvotes: 0

Nic Gibson
Nic Gibson

Reputation: 7143

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.

Upvotes: 0

Related Questions