You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Arundhati Bhowmick <ar...@hyperreal.org> on 2000/02/02 00:14:55 UTC

Using DOM_NodeIterator

Mike,
What are you using as parent_node here? Can you also send me the xml
file that's giving this problem?

Arundhati
Java Technology Center, Silicon Valley -- XML Technology Group
Internet: aruna1@us.ibm.com
1-408-777-5830


----- Original Message -----
From: KRAUSE,MIKE  (HP-FtCollins,ex1)
To: xerces-dev@xml.apache.org
Sent: Friday, January 28, 2000 6:17 PM
Subject: Using DOM_NodeIterator

Hi,

I'm  trying to use the DOM Level 2 DOM_NodeIterator class to iterate
through a  sub-tree.  I only want element nodes.  What I am getting are
element  nodes and #text nodes and I don't know why.  Here is what I'm
doing:

class  MyFilter : public DOM_NodeFilter {
   FilterAction acceptNode(DOM_Node node);
};

DOM_NodeFilter::FilterAction  MyFilter::acceptNode(DOM_Node node) {
 if (node.getNodeType() ==  DOM_Node::ELEMENT_NODE) {
  return  DOM_NodeFilter::ACCEPT;
 } else {
  return  DOM_NodeFilter::SKIP;
 }
}

MyFilter filter;
DOM_NodeIterator  iter=doc.createNodeIterator(parent_node,
DOM_NodeIterator::SHOW_ELEMENT,  filter);

DOM_Node  node;
while  ((node = iter.nextNode()) != 0) {
   // Assuming that I get ELEMENT_NODEs only, but get #text nodes  too!
}


Any  ideas on why I'm getting the extra nodes here?

Regards,

Mike  Krause
Hewlett-Packard Company