Re: [xml] Interating over all children of a given node?

On Tue, Jun 12, 2001 at 03:10:50PM +0200, Gabriel Ambuehl wrote:

I wonder what the easiest way to iterate over all direct children of
node is. Is there any possibility to obtain a NodeSet of the children
to allow easy iteration?

  xmlNodePtr current, child;

  current = ....
  child = current->children;
  while (child != NULL) {
     /* handle child, especially looking at child->type first */

     child = child->next;

I'm not sure adding a function would be any cleaner, one would need to
allocate the memory for the array, let the user free it (dangerous or
one need to handle the case where the caller allocate the array but
this may be too small ...). Iterating on an array is only barely simpler
the only distinctive advantage would be random access.

Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml Gnome XML XSLT toolkit | Rpmfind RPM search engine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]