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



Daniel Veillard wrote:

  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.

  Hello Daniel, All,

 Like Gabriel I was confused when I started using libxml because of the
lack of FUNCTIONS to do such basic tree walk, and the lack of
documentation
therof (except "reading the example code").
 IMHO this is a bad design choice to manipulate struct fields directly.
It
would be a lot cleaner and easier to understand if the previous code
snippet
could be written like :

  xmlNodePtr current, child;

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

     child = child->getNextSibling(child);
  }

 Of course it looks like OO programming and you may dislike that.
However I think
this should be taken into account for the next major (ie incompatible)
release
of libxml.

 Regards,

        Fabrice

-- 
Fabrice Desré - France Telecom R&D/DMI/GRI
Tel: +(33) 2 96 05 31 43
Fax: +(33) 2 96 05 32 86




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