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 "Nathan Beyer (JIRA)" <xe...@xml.apache.org> on 2005/06/17 05:27:28 UTC

[jira] Updated: (XERCESJ-1033) Empty CDATA section is not retrievable (child is null)

     [ http://issues.apache.org/jira/browse/XERCESJ-1033?page=all ]

Nathan Beyer updated XERCESJ-1033:
----------------------------------

    Attachment: bug_1033_patch.txt

The attached patch is a small modification that should resolve this issue, assuming the creation of an empty CDATA node is correct according to the specification.

The path was diffed against the Xerces-J_2_6_2 CVS tag.

> Empty CDATA section is not retrievable (child is null)
> ------------------------------------------------------
>
>          Key: XERCESJ-1033
>          URL: http://issues.apache.org/jira/browse/XERCESJ-1033
>      Project: Xerces2-J
>         Type: Bug
>   Components: DOM
>     Versions: 2.6.2
>  Environment: JDK 1.4.2
>     Reporter: Detlev Beutner
>  Attachments: bug_1033_patch.txt
>
> If a CDATA section is empty, ie <![CDATA[]]>, it is not possible to retrieve this node (eg by getFirstChild()). Instead, null is returned.
> From org.w3c.dom.Node javadoc, getFirstChild() only returns null if there is *no* child. And if there is a CDATA section child, getNodeValue returns "content of the CDATA Section", so in this case by getFirstChild().getNodeValue() an empty string must be returned. In fact, by this call, a NullPointerException gets thrown.
> XML-test-document:
> -----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----
> <test><![CDATA[]]></test>
> -----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----
> Java-test-program:
> -----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
> import org.w3c.dom.Node;
> public class XercesTester {
>     public static void main(String[] args) {
>         try{
>             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>             DocumentBuilder parser = factory.newDocumentBuilder();
>             Document doc = parser.parse("c:/test.xml");
>             Element testNode = doc.getDocumentElement();
>             System.out.println("Test Root Node: " + testNode.getNodeName());
>             System.out.println("Node Value of Root Node: " + testNode.getNodeValue());
>             Node cDataNode = testNode.getFirstChild();
>             if (cDataNode == null) {
>                 System.out.println("CDATA Node is null - everything stopped, xml implementation failed!");
>             } else {
>                 System.out.println("CDATA Node: " + cDataNode.getNodeName());
>                 System.out.println("Node Value of CDATA Node: ---" + cDataNode.getNodeValue() + "---");
>             }
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> }
> -----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----cut-----

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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