Hi all,

I have a  little problem with the NodeList implementation.

If i use node.getElementsByTagName("test").item(0) and no node named "test"
exist this function should return null - see NodeList definition of w3c dom.

In your current implementation, downloaded version 1.4, using of this method
get an index out of bound exception from the DOMNodeHelper class.

I patched the  DOMNodeHelper.createNodeList method:   

public static NodeList createNodeList( final List list ) {
        return new NodeList() {
            public org.w3c.dom.Node item(int index) {
                org.w3c.dom.Node  answer = null;
                try  {
                   answer =  DOMNodeHelper.asDOMNode((Node) list.get( index
));
                } catch (Exception e) {
                }                       
                return answer;
            }
            public int getLength() {
                return list.size();
            }
        };
    }




============================================================================
=================================
Interface NodeList
The NodeList interface provides the abstraction of an ordered collection of
nodes, without defining or constraining how this collection is implemented.
NodeList objects in the DOM are live.

The items in the NodeList are accessible via an integral index, starting
from 0. 


IDL Definition
interface NodeList {
  Node               item(in unsigned long index);
  readonly attribute unsigned long   length;
};



Attributes 
length of type unsigned long, readonly 
The number of nodes in the list. The range of valid child node indices is 0
to length-1 inclusive.

Methods 
item 
Returns the indexth item in the collection. If index is greater than or
equal to the number of nodes in the list, this returns null.
Parameters 
index of type unsigned long
Index into the collection.

Return Value 
Node
 The node at the indexth position in the NodeList, or null if that is not a
valid index.
 

No Exceptions   



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to