You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Donatas Ciuksys <do...@maf.vu.lt> on 2001/08/02 18:31:38 UTC

Crimson bug: Wrong creation of CDATA sections

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