You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2001/12/15 13:09:29 UTC

DO NOT REPLY [Bug 5439] New: - CDATA truncation when using getNodeValue()

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5439>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5439

CDATA truncation when using getNodeValue()

           Summary: CDATA truncation when using getNodeValue()
           Product: Xerces2-J
           Version: 2.0.0 [beta 3]
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Major
          Priority: Other
         Component: DOM
        AssignedTo: xerces-j-dev@xml.apache.org
        ReportedBy: pwalker@PureEdge.com


CDATA data truncates after first newline when using (CDATA_SECTION_NODE) 
getNodeValue() method.  This method truncates when using the Xerces2 2.0.0 
(beta3) Java Parser with the JAXP-Xalan 1.1 released by Sun, and it also 
truncates with the dom/Writer Xerces (non-JAXP) sample applications (It works 
in the sax/Writer sample).

This problem does not occur with Crimson+JAXP(Xalan) and Saxon(AElfred)+JAXP.

DETAILED DESCRIPTION FOLLOWS:
C:\Java\bug>type cdata.xml
<?xml version='1.0' encoding='utf-8'?>
<slideshow>
    <slide type="tech">
      <item><![CDATA[Diagram:

    frobmorten <------------ fuznaten
        |            <3>        ^
        | <1>                   |   <1> = fozzle
        V                       |   <2> = framboze
      staten--------------------+   <3> = frenzle
                     <2>
      ]]></item>
    </slide>
</slideshow>

C:\Java\bug>type CDATAbug.java
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import java.io.File;
import java.io.IOException;

import org.w3c.dom.*;

/* Demonstrate possible CDATA bug in Xerces2 Java Parser 2.0.0 (beta3) Release 
*/
/* O/S: Microsoft Windows 2000, build 5.00.2195, Service Pack 2                
*/
/* HW : IBM A20m ThinkPad, 128MB RAM                                           
*/
/* NOTE: XML example a fragment from Sun's JAXP DOM tutorial                   
*/
public class CDATAbug
{
   static Document document;

   public static void main(String argv[])
   {
      if (argv.length != 1) {
         System.err.println("Usage: java CDATAbug [filename]");
         System.exit(1);
      }

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
         DocumentBuilder builder = factory.newDocumentBuilder();
         document = builder.parse( new File(argv[0]) );

      } catch (SAXException sxe) {
         System.out.println("Problem parsing the file.");
         System.exit(1);
      } catch (ParserConfigurationException pce) {
         System.out.println("The parser was not configured correctly.");
         System.exit(1);
      } catch (IOException ioe) {
         System.out.println("Cannot read input file.");
         System.exit(1);
      } catch (java.lang.IllegalArgumentException ae) {
         System.out.println("Please specify an XML source.");
         System.exit(1);
      }

      if (document != null)
         printDOMTree( document );
   }

   private static void printDOMTree (Node node)
   {
      int type = node.getNodeType();
      switch (type) {
         // ignore document element
         case Node.DOCUMENT_NODE: {
            printDOMTree(((Document)node).getDocumentElement());
            break;
         }
         // ignore element with attributes
         case Node.ELEMENT_NODE: {
            NodeList children = node.getChildNodes();
            if (children != null) {
               int len = children.getLength();
               for (int i = 0; i < len; i++)
                  printDOMTree(children.item(i));
            }
            break;
         }
         // print CDATA sections
         case Node.CDATA_SECTION_NODE: {
            System.out.print("<![CDATA["+ node.getNodeValue() +"]]>");
            break;
         }
      }
      return;
   }
}

C:\Java\bug>xerces_jaxp-xalan.bat
C:\Java\bug>set CLASSPATH
CLASSPATH=C:\jdk1.3.1
\jre\lib\rt.jar;.;C:\java\xerces\xerces.jar;C:\java\xerces\xercesSamples.jar;C:\
java\jaxp\xalan.jar

C:\Java\bug>java CDATAbug cdata.xml
<![CDATA[Diagram:]]>
C:\Java\bug>java dom/Writer -p dom.wrappers.Xerces -S cdata.xml
<?xml version="1.0" encoding="UTF-8"?>
<slideshow>
    <slide type="tech">
      <item><![CDATA[Diagram:]]></item>
    </slide>
</slideshow>

C:\Java\bug>java sax/Writer -p org.apache.xerces.parsers.SAXParser -S cdata.xml
<?xml version="1.0" encoding="UTF-8"?>
<slideshow>
    <slide type="tech">
      <item>Diagram:

    frobmorten &lt;------------ fuznaten
        |            &lt;3&gt;        ^
        | &lt;1&gt;                   |   &lt;1&gt; = fozzle
        V                       |   &lt;2&gt; = framboze
      staten--------------------+   &lt;3&gt; = frenzle
                     &lt;2&gt;
      </item>
    </slide>
</slideshow>

C:\Java\bug>saxon.bat
C:\Java\bug>set CLASSPATH
CLASSPATH=C:\jdk1.3.1
\jre\lib\rt.jar;.;C:\java\saxon\saxon.jar;C:\java\jaxp\xalan.jar

C:\Java\bug>java CDATAbug cdata.xml
<![CDATA[Diagram:

    frobmorten <------------ fuznaten
        |            <3>        ^
        | <1>                   |   <1> = fozzle
        V                       |   <2> = framboze
      staten--------------------+   <3> = frenzle
                     <2>
      ]]>

C:\Java\bug>crimson_jaxp-xalan.bat
C:\Java\bug>set CLASSPATH
CLASSPATH=C:\jdk1.3.1
\jre\lib\rt.jar;.;C:\Java\jaxp\crimson.jar;C:\java\jaxp\xalan.jar

C:\Java\bug>java CDATAbug cdata.xml
<![CDATA[Diagram:

    frobmorten <------------ fuznaten
        |            <3>        ^
        | <1>                   |   <1> = fozzle
        V                       |   <2> = framboze
      staten--------------------+   <3> = frenzle
                     <2>
      ]]>

C:\Java\bug>

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org