[libxml++] problem returning a node
- From: Josh Tharp <joshtharp gmail com>
- To: libxmlplusplus-general lists sourceforge net
- Subject: [libxml++] problem returning a node
- Date: Thu, 29 Sep 2005 18:38:35 -0500
I have a domparser setup and it parses my xml file fine without any
error. I can transverse through the doc tree fine with
parser.get_document()->get_root_node() and iterating using the
recursion example provided in the docs.
What i am having trouble with is breaking up different parsing tasks into functions.
In my function:
const xmlpp::Node* RssData::getElementTag(const xmlpp::Node* node, const Glib::ustring tagname)
{
std::cout<<"Node loop: get_name()node: "<<node->get_name()<<std::endl;
xmlpp::Node::NodeList nlist = node->get_children();
if(!nlist.empty())
{
for(xmlpp::Node::NodeList::const_iterator itr = nlist.begin(); itr != nlist.end(); ++itr)
{
if((*itr)->get_name() == tagname)
{
std::cout<<"Title tag found try to
return"<<std::endl;
return (*itr);
}
else
getElementTag((*itr), tagname);
}
}
}
The function is able to find a matching node and will return without
errors but it does not return a valid address to a node in the
doctree. I get a seg fault after trying to use the node pased
from getElementTag (eg node->get_name() will segfault because it
does not point to a valid address).
the function is passed a const node pointer returned from
parser.get_document()->get_root_node() and a string tagname to match
against a node. It will transverse the tree till it finds a
matching node and try to return a pointer to that node so it can be use
elsewhere.
I'm not sure if nodelist is a copy of node's children and thus when the
function ends they are no longer accessible, but i understand them to
be a list<node*> right?
I am sorry if this is a simple logic error, just trying to get past this.
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]