You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Christian Geuer-Pollmann <ma...@nue.et-inf.uni-siegen.de> on 2002/05/23 11:21:33 UTC

Set vs. NodeList

Hi all,

in the "Apache xml-security" project, I must perform many operations on 
XPath node sets. Many operations are questions in the form:

    "Is the Node 'n' in the nodeset selected by the
     following XPath expression?".

At the moment, to do this task, I do the following:

NodeList selectedNodes = cachedXPathAPI.selectNodeList(doc, 
xpathExpression, nsContext);
java.util.Set set = new java.util.HashSet();
for (int i=0; i<selectedNodes; i++) {
   set.add(selectedNodes.item(i);
}

This means I get my selected nodes in a list-like structure and then I have 
to copy all nodes to the Set, which costs me much time. After that copy 
operation, I can easily ask:

Node particularNode = ...;
boolean contained = selectedNodes.contains(particularNode);

My question to the Xalan XPath gurus out there:

   "Is there a way to handle such tasks more efficiently?"


Regards (and thanks in advance),
Christian