You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by chris schaefer <ch...@seacoms.com> on 2000/12/13 07:36:41 UTC

Node interators

Hello:
   I'm having trouble with some of my code which uses a nested series of
Node_Iterators.    for example ( this will probably be real ugly in the
email...):

 DOM_Document doc = pDOMparser->getDocument();
  DOM_Node node = doc.getFirstChild();
DOM_NodeIterator DNI =
doc.createNodeIterator(node,DOM_NodeFilter::SHOW_ELEMENT, (DOM_NodeFilter*)new
MyDomNodeFilter("ZoneConf"),true);
      DOM_Node aFoundNode;
      while( (aFoundNode = DNI.nextNode()) != NULL ) {
           DOM_NodeIterator DNI2 = doc.createNodeIterator(aFoundNode,
DOM_NodeFilter::SHOW_ELEMENT, (DOM_NodeFilter*)new
MyDomNodeFilter("Zone"),true);
          DOM_Node aZoneNode;
           while( (aZoneNode = DNI2.nextNode()) != NULL ) {
                    // do something fun with the "Zone" elements
            }
        }

The problem that I'm having is that I'm not getting the inner iterator to only
iterate through nodes which are "below" the node passed in as "root".  ( in
the example above, the second iterator incorrectly finds ALL instances of
"Zone"  not just instances which are below "ZoneConf"   )    My understand, is
that this is supposed to happen. Am I incorrect in this assumption?  if not,
what am I doing wrong?

-C-

Re: probably a bug in createNodeIterator

Posted by chris schaefer <ch...@seacoms.com>.
Ah you are right!

I got so excited that I'd found a bug, that I forgot that I was running an older revision, and that someone else had probably already
fixed it.     The new revision fixes all my reproduction cases.

-C-


Gareth Reakes wrote:

> Hello,
>         I believe that bug has been fixed. Try downloading the nightly
> build.
>
> Gareth
>
> On Wed, 13 Dec 2000, chris schaefer wrote:
>
> > I now believe there is a bug in the tree walking code contained here:
> >
> > NodeIteratorImpl::nextNode (DOM_Node node, bool visitChildren)
> > lines 327  forward
> > in NodeIteratorImpl.cpp
> >
> > Apparently if root node passed into the createIterator then we get the following sequence:
> > 1) first time through  this function returns fRoot - correctly
> > 2) second time through this function returns the next sibling of the parent of fRoot, instead of NULL which is what it should do.
> >
> >
> > -C-
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org

Re: probably a bug in createNodeIterator

Posted by Gareth Reakes <ga...@decisionsoft.com>.
Hello,
	I believe that bug has been fixed. Try downloading the nightly
build.

Gareth

On Wed, 13 Dec 2000, chris schaefer wrote:

> I now believe there is a bug in the tree walking code contained here:
> 
> NodeIteratorImpl::nextNode (DOM_Node node, bool visitChildren)
> lines 327  forward
> in NodeIteratorImpl.cpp
> 
> Apparently if root node passed into the createIterator then we get the following sequence:
> 1) first time through  this function returns fRoot - correctly
> 2) second time through this function returns the next sibling of the parent of fRoot, instead of NULL which is what it should do.
> 
> 
> -C-
> 


Re: probably a bug in createNodeIterator

Posted by chris schaefer <ch...@seacoms.com>.
I now believe there is a bug in the tree walking code contained here:

NodeIteratorImpl::nextNode (DOM_Node node, bool visitChildren)
lines 327  forward
in NodeIteratorImpl.cpp

Apparently if root node passed into the createIterator then we get the following sequence:
1) first time through  this function returns fRoot - correctly
2) second time through this function returns the next sibling of the parent of fRoot, instead of NULL which is what it should do.


-C-

probably a bug in createNodeIterator

Posted by chris schaefer <ch...@seacoms.com>.
Hi All:
    First off, thank Khaled for you reply!  got me looking into the right
places!!!!

   I've finally cut away all of the unimportant parts of my code and I'm left with
what I believe to be heart of the problem.   I'm still not clear what is causing
the problem though I think I understand the symptoms well.

It appears as though if I pass in an empty element  (   for example
<HostInZone/>   )  or a normal element pair with no white space ( for example
<HostInZone></HostInZone>  )  to the createNodeIterator as the "root" parameter
then the createNodeIterator will proceed to use REST of the document as the area in
which to search for stuff which is accepted by the filter.

My belief is that this is incorrect behavior.   What I would expect is that if the
root node is "empty" ( meaning has no children: elements or ignorable white space )
then the iterator would return a NULL node the first time nextNode is called.

I'd love to be able to dig into the xerces code and and figure out what the exact
bug is on this one, and I'll probably attempt to figure it out myself in the spirit
of OSS.   However, since my expectation is that it's buried deep within code I've
never seen,  I'll send along my XML and my modified DOMPrint code, and hope that
someone else can also look into this.

The XML demonstrates several different way the failure can manifest itself, I would
recommend simplfying things a bit if you want to actually debug.   If the bug gets
fixed, this XML should deliver ONLY the nodes which have roles equal to something
that I want.

-C-

Re: Node interators

Posted by Khaled Noaman <kn...@ca.ibm.com>.
Hi Chris,

The DOM_NodeIterator will iterate through child nodes of the root element
specified, and your inner iterator should only return nodes that are below
"ZoneConf". It would be helpful if you can include a sample of the xml document
you are parsing. I have modified the DOMPrint sample to simulate your situation
and the DOM_NodeIterator is working as expected. The inner iterator is only
returning the child "Zone" nodes for a given "ZoneConf" node. I am attaching the
DOMPrint.cpp and sample xml file that I used for your reference. Give it a try.


Regards,
Khaled Noaman
XML Parser Dev.- IBM Toronto Lab
knoaman@ca.ibm.com

chris schaefer wrote:

> Hello:
>    I'm having trouble with some of my code which uses a nested series of
> Node_Iterators.    for example ( this will probably be real ugly in the
> email...):
>
>  DOM_Document doc = pDOMparser->getDocument();
>   DOM_Node node = doc.getFirstChild();
> DOM_NodeIterator DNI =
> doc.createNodeIterator(node,DOM_NodeFilter::SHOW_ELEMENT, (DOM_NodeFilter*)new
> MyDomNodeFilter("ZoneConf"),true);
>       DOM_Node aFoundNode;
>       while( (aFoundNode = DNI.nextNode()) != NULL ) {
>            DOM_NodeIterator DNI2 = doc.createNodeIterator(aFoundNode,
> DOM_NodeFilter::SHOW_ELEMENT, (DOM_NodeFilter*)new
> MyDomNodeFilter("Zone"),true);
>           DOM_Node aZoneNode;
>            while( (aZoneNode = DNI2.nextNode()) != NULL ) {
>                     // do something fun with the "Zone" elements
>             }
>         }
>
> The problem that I'm having is that I'm not getting the inner iterator to only
> iterate through nodes which are "below" the node passed in as "root".  ( in
> the example above, the second iterator incorrectly finds ALL instances of
> "Zone"  not just instances which are below "ZoneConf"   )    My understand, is
> that this is supposed to happen. Am I incorrect in this assumption?  if not,
> what am I doing wrong?
>
> -C-
>
>   ------------------------------------------------------------------------
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org