java项目不允许使用字符串" - "

use*_*246 2 java xml string parsing

可能重复:
治愈'字符串' - "评论中不允许".例外?

我有一个Java项目来解析和编辑XML文件.当我尝试运行该项目时,我收到以下日志消息:

The string "--" is not permitted within comments.
Exception in thread "main" org.xml.sax.SAXParseException: The string "--" is not permitted within comments.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:246)
...

我该如何解决?

Sir*_*rko 8

无需进一步了解您的代码:

你被告知有错误.在XML表格的某处,您有一个注释,其中包含一个注释--.例如这样的事情:

<root>
  <!-- my comment with -- in it -->
</root>
Run Code Online (Sandbox Code Playgroud)

这不是一个格式良好的XML.--不允许在评论中.解析器在检测注释结束时会遇到问题.

  • 你可以解释为什么解析器很难吗?我的意思是" - >"定义了评论的结尾.那么为什么解析器不仅忽略了" - "而且进一步观察? (2认同)
  • @Timo +1评论,我只是搜索并发现他们保持这样保持与SGML兼容 (2认同)
  • @Timo:因为它指定了与SGML兼容的方式:http://www.w3.org/TR/xml/#sec-comments (2认同)