this is the tag in xml
<content>The Avengers</content>
i want to take out "The Avengers" from the tag using xpath from libxml2 in c++
Here is my code
xmlXPathObject * xpathObj = xmlXPathEvalExpression( (xmlChar*)"/content", xpathCtx );
if ( xpathObj == NULL ) throw "failed to evaluate xpath";
for(int i=0;i<=0; i++)
{
xmlNode *node = NULL;
if ( xpathObj->nodesetval && xpathObj->nodesetval->nodeTab )
{
node = xpathObj->nodesetval->nodeTab[i];
std::cout << "Found the node we want" << std::endl;
}
else
{throw "failed to find the expected node";}
xmlAttr *attr = node->properties;
while ( attr )
{
std::cout << "Attribute name: " << attr->name << " value: " << attr->children->content << std::endl;
attr = attr->next;
}
xmlSetProp( node, (xmlChar*)"age", (xmlChar*)"3" );
}
its work fine and reached easily at content tag but not showing the data between the tag
RESULT
<content age="3">The Avengers</content>
but in console its shows nothing Thanks
No comments:
Post a Comment