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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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?
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setIgnoringComments(true); docFactory.setValidating(false); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.parse(file);
@Timo +1 for comment, I just searched and found that they kept it like this to remain compatible with SGML
@Timo: Because its specified that way for compatibility with SGML: w3.org/TR/xml/#sec-comments
there is no way to resolve this?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.