[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnu.xml.dom.DomText implements Text and NodeList.
From: |
Chris Burdess |
Subject: |
Re: gnu.xml.dom.DomText implements Text and NodeList. |
Date: |
Wed, 4 Jan 2006 07:16:19 +0000 |
User-agent: |
Mutt/1.5.10i |
Pedro Izecksohn wrote:
> DomText implements Text and NodeList.
>
> The problem is that method getLength() from interfaces NodeList and Text
> have different meanings.
>
> Text.getLength() must return the text content length in characters.
> NodeList.getLength() must return the number of nodes it contains.
>
> From DOM Level 3 Core Specification:
>
> "Some types of nodes ... are leaf nodes that cannot have anything below them
> in the document structure."
>
> "Text -- no children"
>
> From "C.6.1 Infoset to Text Node" I understand that for any Text,
> text.getChildNodes() must return a NodeList whose getLength() equals 0.
>
> The problem appears in SableVM classpath because for gnu.xml.dom.DomNode,
> node.getChildNodes() returns itself.
>
> My proposed solution is:
>
> Add to gnu.xml.dom.DomText:
>
> import org.w3c.dom.NodeList;
>
> /**
> * Returns an EmptyNodeList.
> *
> * @author Pedro Izecksohn
> */
> public NodeList getChildNodes()
> {
> return (NodeList) new EmptyNodeList();
> }
>
> Add to gnu/xml/dom/ the file EmptyNodeList.java:
>
> package gnu.xml.dom;
>
> import org.w3c.dom.Node;
> import org.w3c.dom.NodeList;
>
> /**
> * @author Pedro Izecksohn
> */
>
> public final class EmptyNodeList implements NodeList
> {
>
> public EmptyNodeList () {}
>
> public final int getLength () {return 0;}
>
> public final Node item (int index) {return null;}
>
> }
That looks absolutely correct.
--
Chris Burdess
"They that can give up essential liberty to obtain a little safety
deserve neither liberty nor safety." - Benjamin Franklin
pgp5M7ZfxTkGK.pgp
Description: PGP signature