xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Donatas Ciuksys" <donatas.ciuk...@maf.vu.lt>
Subject Crimson bug: Wrong creation of CDATA sections
Date Thu, 02 Aug 2001 16:31:38 GMT
Hello,

I find following bug of crimson parser: method Document.createCDATASection(String data)
creates wrong CDATA sections if parameter data contains sequence "]]>". For example, if
we
will pass string "blah]]>blah", it will create:

    <![CDATA[blah]]]]><![CDATA[>]>blah]]>

what is equivalent of "blah]]>]>blah".
Bellow is code example:

import java.io.*;

import javax.xml.parsers.*;
import org.xml.sax.*;
import org.w3c.dom.*;

public class TestCrimson {
    public static void main(String[] args) throws Exception {
        DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();

        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        DOMImplementation domImplementation = documentBuilder.getDOMImplementation();

        /*
         * Lets create new document:
         */
        DocumentType doctype =
            domImplementation.createDocumentType(
                "TestCrimson", // qualifiedName
                null,                // publicId
                null                 // systemId
            );
        Document newDocument =
            domImplementation.createDocument(
                null,          // namespaceURI
                "TestCrimson", // qualifiedName
                doctype        // doctype
            );

        /*
         * Create CDATA section:
         */
        CDATASection cdataSection = newDocument.createCDATASection("blah]]>blah");
        newDocument.getDocumentElement().appendChild(cdataSection);

        /*
         * Write document to file:
         */
        PrintWriter writer = new PrintWriter(new FileOutputStream("doc.xml"));
        ((org.apache.crimson.tree.XmlDocument)newDocument).write(writer);
        writer.close();
    }
}

The generated document will be:

<?xml version="1.0"?>

<!DOCTYPE TestCrimson>

<TestCrimson>
  <![CDATA[blah]]]]><![CDATA[>]>blah]]>
</TestCrimson>


Regards,
Donatas


---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message