2

Possible Duplicate:
Cure for ‘The string “--” is not permitted within comments.’ exception?

I have a Java project to parse and edit XML files. When I try to run the project I get the following log message:

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)
...

How can I resolve it?

Community
  • 1
  • 1
user1918246
  • 41
  • 1
  • 1
  • 2

1 Answers1

8

Without further knowing your code:

There error is as you were told. Somewhere in your XML sheet, you have a comment, which includes a -- in it. For example something like this:

<root>
  <!-- my comment with -- in it -->
</root>

This is not a well formed XML. Within a comment -- is not allowed. The parser will have problems to detect the end of the comment then.

Sirko
  • 72,589
  • 19
  • 149
  • 183
  • 2
    May you can explain why it's difficult for the parser? I mean "-->" defines the end of the comment. So why is the parser not just ignoring the "--" and looking further? – xoned Dec 20 '12 at 09:29
  • DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setIgnoringComments(true); docFactory.setValidating(false); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.parse(file); – user1918246 Dec 20 '12 at 09:42
  • 2
    @Timo +1 for comment, I just searched and found that they kept it like this to remain compatible with SGML – vishal_aim Dec 20 '12 at 09:51
  • 2
    @Timo: Because its specified that way for compatibility with SGML: http://www.w3.org/TR/xml/#sec-comments – Jörn Horstmann Dec 20 '12 at 09:52
  • there is no way to resolve this? – user1918246 Dec 20 '12 at 13:00