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 YeowCheong Pua <pu...@usa.net> on 2000/09/29 16:10:03 UTC
Question about NodeList
Hi
I'm using XML4J3.0.1 downloaded from alphaworks. I encountered this (strange?)
behaviour in the following method.
/**
* Encrypt all nodes that has nodeName
*/
public static Document encrypt(Document pXML, String nodeName){
Element root = pXML.getDocumentElement();
NodeList children = root.getElementsByTagName(nodeName);
Node child = null;
if(children != null){
for(int i=0;i<children.getLength();i++){
child = children.item(i);
encrypt(pXML,child);
}
return pXML;
}
else
return null;
}
This method encrypt all elements with tag name equals to nodeName in the pXML
Document. The tag name of the element changes (to an encrypted value) after it
is encrypted.
The strange behaviour is that the value of children.getLength() decrement by 1
at each iteration in the for loop. The encrypted node is dropped, and all the
unencrypted nodes moves up by one in the items list. It seems that the
NodeList's getLength() method checks through the Document and updates its
items each time it is called (and not only at getElementsByTagName).
Is this a correct behaviour? Can I assume that future version of XML Parsers
will always behave in the same way?
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1