简体   繁体   English

解析 cXML 文件

[英]Parse cXML file

As a response I am getting the below cXML, and its not getting parse if I am using XSLT.作为响应,我得到以下 cXML,如果我使用 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.无法使用提供的 XML/XSL 输入生成 XML 文档。 org.xml.sax.SAXParseException; org.xml.sax.SAXParseException; systemId: http://xml.cxml.org/schemas/cXML/1.2.046/cXML.dtd; systemId: http://xml.cxml.org/schemas/cXML/1.2.046/cXML.dtd; lineNumber: 1;行号:1; columnNumber: 1;列数: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我的要求是得到一个 output XML 之类的

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

can you let me know the XSLT for that.你能告诉我 XSLT 吗?

在此处输入图像描述

Thanks Yatan谢谢 Yatan

If your input document is literally what you have shown above, you'll need to remove all the whitespace before the xml declaration.如果您的输入文档确实如上所示,则需要删除 xml 声明之前的所有空格。 The can be nothing before the declaration.在声明之前可以什么都没有。

I was unable to parse this via XSLT, finally used the below expression before using the XSLT to remove it from XML.我无法通过 XSLT 解析它,最后在使用 XSLT 将其从 XML 中删除之前使用了以下表达式。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM