[jdom-interest] Parsing a comment like <!--- Hello

Elias Ross eross at m-Qube.com
Tue Nov 2 14:16:28 PST 2004


Somebody created a configuration file with a comment like this

<!--- This is a comment -->

It passed validation with xmllint.  JDom however will *not* parse this
comment.  (This is valid XML, by the way.)

What happened was we tried to read this configuration file and blew up
unexpectedly.  JDom and xmllint (and other XML parsers) should agree.

src/java/org/jdom/Verifier.java:485

    public static String checkCommentData(String data) {
        String reason = null;
        if ((reason = checkCharacterData(data)) != null) {
            return reason;
        }

        if (data.indexOf("--") != -1) {
            return "Comments cannot contain double hyphens (--)";
        }
        if (data.startsWith("-")) {
            return "Comment data cannot start with a hyphen.";
        }
        if (data.endsWith("-")) {
            return "Comment data cannot end with a hyphen.";
        }
                                                                                                                                                               
        // If we got here, everything is OK
        return null;
    }




More information about the jdom-interest mailing list