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 2004/03/04 22:08:54 UTC

DO NOT REPLY [Bug 27454] New: - Traversing the DOM throws NullPointerException

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=27454>.
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=27454

Traversing the DOM throws NullPointerException

           Summary: Traversing the DOM throws NullPointerException
           Product: Xerces2-J
           Version: 2.6.2
          Platform: PC
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: Other
         Component: DOM
        AssignedTo: xerces-j-dev@xml.apache.org
        ReportedBy: mhemani@ca.ibm.com


I'm traversing a Document parsed by the DOMParser and running into 
NullPointerExceptions. 

The exception occurs at 
     org.apache.xerces.dom.ParentNode.nodeListItem(Unknown Source)
     org.apache.xerces.dom.ParentNode.item(Unknown Source)

Sometimes is it also seen when 'NodeList.getLength()' is called.

The traversing is done using a for loop and recursing into the routine, 
EXAMPLE:
========
Node findNode(Node parentNode) {

NodeList childNodes = parentNode.getChildNodes();

for(int i = 0; i < childNodes.getLength(); i++) {
    Node child = childNodes.item(i);

    if (child != null && child.getNodeType != Node.ELEMENT_NODE) {
        continue;
    }
    else {
        // do something
        ...
        ...
    }
}

// Then recursively call the above routine
for (int i = 0; i < childNodes.getLength(); i++) {
    Node child = childnodes.item(i);
    
    if (child != null) {
        Node found = findNode(child);
        // more code to follow
        ...
        ...
    }
}

}

If you need the sample XML document, I prefer to email it you.
Thanks.

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