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 jr...@hauppauge.com on 2001/08/30 00:17:36 UTC

My own node list?

Hi,

I'm not sure what the best way to accomplish this task is.  I would like to
create my own node list by collecting nodes from various DOM API's.  Then
I'd like to use those nodes by passing the list around to different
functions in my code.


I know the following will not work:

	DOM_NodeList domNodeList = getAllChildNodes();
	DOMString dsTemp,dsName;
	dsName = transcode("someNameImLookingFor);
	int listLength = domNodeList.getLength();
	
	for(int i= 0; i<listLength ;i++){
		if(dsName.equals(domNodeList.item(i).getNodeName())) {
			// myNodeList is a linked list of DOM_Node *
			myNodeList->append(&(domNodeList.item(i)) );
		}
	}

Here I'm keeping a list of DOM_Node pointers which from what I've read on
this list archive as well as the doc's is a very bad thing to do.  

I came across a post from Joseph_Kesselman@lotus.com that contained this
snippet:

    for (Node n=myparentelement.getFirstChild();
          n!=null;
          n=n.getNextSibling() )
     {
          if(givenTagname.equals(n.getNodeName()))
          {
               ...process it, or add to a list for later processing...
          }
     }

Note that he says "...process it, or add to a list for later processing...
This is what I want to do, but how do I construct and use the list he is
talking about.

I'm getting the feeling that I should probably avoid all this by using a
treewalker or nodeiterator, but I would still like to know how to keep my
own list.

Thanks,

John

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


Re: My own node list?

Posted by "Scott A. Herod" <he...@interact-tv.com>.
Hi John,

Why not have a class that responsible for maintaining the DOM list and
have everything else make calls into it.  That way you also hide all of
the xerces specific code in case you later need to swap out with another
parser.  Also, if you want to thread your code, you'll need to protect
the DOM structure and the class you build would be able to handle that.

We use something similar to this in our main app.  I'd be happy to give
you more details if you wish.

Scott
herod@interact-tv.com

jrodriguez@hauppauge.com wrote:
> 
> Hi,
> 
> I'm not sure what the best way to accomplish this task is.  I would like to
> create my own node list by collecting nodes from various DOM API's.  Then
> I'd like to use those nodes by passing the list around to different
> functions in my code.
> 
> I know the following will not work:
> 
>         DOM_NodeList domNodeList = getAllChildNodes();
>         DOMString dsTemp,dsName;
>         dsName = transcode("someNameImLookingFor);
>         int listLength = domNodeList.getLength();
> 
>         for(int i= 0; i<listLength ;i++){
>                 if(dsName.equals(domNodeList.item(i).getNodeName())) {
>                         // myNodeList is a linked list of DOM_Node *
>                         myNodeList->append(&(domNodeList.item(i)) );
>                 }
>         }
> 
> Here I'm keeping a list of DOM_Node pointers which from what I've read on
> this list archive as well as the doc's is a very bad thing to do.
> 
> I came across a post from Joseph_Kesselman@lotus.com that contained this
> snippet:
> 
>     for (Node n=myparentelement.getFirstChild();
>           n!=null;
>           n=n.getNextSibling() )
>      {
>           if(givenTagname.equals(n.getNodeName()))
>           {
>                ...process it, or add to a list for later processing...
>           }
>      }
> 
> Note that he says "...process it, or add to a list for later processing...
> This is what I want to do, but how do I construct and use the list he is
> talking about.
> 
> I'm getting the feeling that I should probably avoid all this by using a
> treewalker or nodeiterator, but I would still like to know how to keep my
> own list.
> 
> Thanks,
> 
> John
>

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