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 =3D node->get_children();
if(!nlist.empty())
{
for(xmlpp::Node::NodeList::const_iterator itr =3D nlist.begin(); itr !=3D
nlist.end(); ++itr)
{
if((*itr)->get_name() =3D=3D 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 se=
g
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 agains=
t
a node. It will transverse the tree till it finds a matching node and try t=
o
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.
|