Re: [xml] search for a match in the tree and return a node pointer
- From: "Zichao Mao" <mzichao hotmail com>
- To: brasilino recife pe gov br
- Cc: xml gnome org
- Subject: Re: [xml] search for a match in the tree and return a node pointer
- Date: Wed, 14 Apr 2004 09:41:05 -0700
another question, how do I define a node pointer as return type? Like, what
should I put here:
(static char*, is this right?) findContent (const char* searchStr,
xmlNodePtr cur)
Thanks.
From: "Zichao Mao" <mzichao hotmail com>
To: brasilino recife pe gov br
CC: xml gnome org
Subject: Re: [xml] search for a match in the tree and return a node pointer
Date: Wed, 14 Apr 2004 09:10:34 -0700
Thank you for your reply, Lucas.
When you say I can return whatever I like: a maching node pointer, a
pointer to content node which is child of maching node...could you give me
an example? I only know how to return the contentitself using
xmlNodeListGetString. What about others?
On the second part, when you say a recursive function would do the trick,
do you mean like this:
for (cur_node = cur; cur_node; cur_node = cur_node->children)
{
head->pair->name = cur->name;
head->pair->content = cur->children->content;
head->next = cur->children;
}
return head;
}
I want to return all the names and contents from the tree to my structure,
head.
Thank you.
From: Lucas Brasilino <brasilino recife pe gov br>
To: Zichao Mao <mzichao hotmail com>
CC: xml gnome org
Subject: Re: [xml] search for a match in the tree and return a node
pointer
Date: Wed, 14 Apr 2004 08:30:57 -0300
Hi,
Hi
I want to search for a match in the tree and return a node pointer. I
don't know what functions to use in libxml2. Here's my code:
??? findContent (const char* searchStr, xmlNodePtr cur)
{
xmlNodePtr cur_node = NULL;
for (cur_node = cur; cur_node; cur_node = cur_node->next)
{
if (!xmlStrcmp(cur->name, (const xmlChar*)searchChar)) return ???;
else if (!xmlStrcmp(cur->name, (const xmlChar*)searchChar)) return ???;
}
}
I didn't undestand. You're using searchStr and checking node's
name against searchChar??! Well, considering it a typo this snippet
seems to work, but be aware both conditionals are equal.
You can return whatever you like: a maching node pointer, a
pointer to content node which is child of maching node, the content
itself (xmlNodeListGetString).
For the sake of consistency, I think findContent() should
be declared using searchStr as const xmlChar * and casts searchStr
when calling findContent().
Then, in the next function, FindAllContents(???) //something like,
xmlNodePtr ptr
{
//location pointer from FindContent() is the input, output returns all
items and contents for that node; what structures or functions should I
use?
}
A code example would be helpful. Thank you.
Since looks like you don't want to use XPath (which should be
*lot* easier) you must walk throught the entire tree, mostly using a lot
of loops :) A recursive function should do the trick.
--
[]'s
Lucas Brasilino
brasilino recife pe gov br
http://www.recife.pe.gov.br
Emprel - Empresa Municipal de Informatica (pt_BR)
Municipal Computing Enterprise (en_US)
Recife - Pernambuco - Brasil
Fone: +55-81-34167078
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar ? get it now!
http://toolbar.msn.com/go/onm00200415ave/direct/01/
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar ? get it now!
http://toolbar.msn.com/go/onm00200415ave/direct/01/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]