[ 
https://issues.apache.org/jira/browse/XERCESJ-1033?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Elliotte Rusty Harold resolved XERCESJ-1033.
--------------------------------------------
    Resolution: Not A Bug

CDATASections are not necessarily separate nodes. It's not wrong to drop an 
empty one. Per spec "When a document is first made available via the DOM, there 
is only one Text node for each block of text." That means CDATA sections are 
necessarily combined with surrounding text. 

> Empty CDATA section is not retrievable (child is null)
> ------------------------------------------------------
>
>                 Key: XERCESJ-1033
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1033
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: DOM (Level 3 Core)
>    Affects Versions: 2.6.2
>         Environment: JDK 1.4.2
>            Reporter: Detlev Beutner
>            Priority: Major
>         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 was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to