From: Daniel Veillard (Daniel.Veillard@w3.org)
Date: Tue Oct 17 2000 - 16:06:33 EDT
On Tue, Oct 17, 2000 at 07:48:27PM +0200, Michael Liehmann wrote:
>
> Hi !
>
> i want to walk through my parsed tree and
> put the tagNames to screen.
>
> here is the according code
>
> goTree( xmlDocGetRootElement(doc), xmlDocGetRootElement(doc));
>
>
> void goTree(xmlNodePtr cur, xmlNodePtr checkEnd) {
>
> printf("%s\n", cur->name);
>
> if ( cur->children->next) {
> goTree(cur->children->next, checkEnd);
> }
> if ( (cur != checkEnd) && (cur->next->next)) {
> goTree(cur->next->next, checkEnd);
> }
> }
Hum, there is multiple examples of tree traversal in tree.c at least
it's a very basic algorithm usually taught in 1st semester course and
walking libxml tree ain't different.
You just get confused by the presence of blanks nodes
-------
<p>
<q/>
</p>
-------
Generates the following tree
Node p
Text node
Node q
Text node
Use xmllint --debug to see it
You seems to not realize that *any* character is significant
including the "white spaces" used for formatting as was repeated
multiple times on the list :-)
Use xmllint --debug to undertand the generated structure,
use then xmllint --noblanks --debug to se what you expected to find
in the first place, then rewrite you algorithm correctly !
You can double check by reading xmlNodeDump() in tree.c for
the solution of the exercise, use the code it's available :-)
daniel
-- Daniel.Veillard@w3.org | W3C, INRIA Rhone-Alpes | libxml gnome XML toolkit Tel : +33 476 615 257 | 655, avenue de l'Europe | http://xmlsoft.org/ Fax : +33 476 615 207 | 38330 Montbonnot FRANCE | Rpmfind search site http://www.w3.org/People/all#veillard%40w3.org | http://rpmfind.net/ ---- Message from the list xml@rpmfind.net Archived at : http://xmlsoft.org/messages/ to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net
This archive was generated by hypermail 2b29 : Tue Oct 17 2000 - 16:43:54 EDT