#include "libxml/parser.h" #include "libxml/tree.h" #include "libxml/xpath.h" void noproblem(const char* xml, const xmlChar* xpath) { xmlDocPtr doc = xmlReadMemory(xml, strlen(xml), 0, 0, 0); if (doc) { xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); if (xpathCtx) { xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(xpath, xpathCtx); if (xpathObj) { xmlBufferPtr buf = xmlBufferCreate(); if (buf) { xmlNodeSetPtr nodes = xpathObj->nodesetval; // could not be nodeset but hey int i, l = nodes ? nodes->nodeNr : 0; for (i = 0; i < l; ++i) { xmlNodeDump(buf, doc, nodes->nodeTab[i], 0, 0); // can error xmlBufferCat(buf, "\n"); } printf(xmlBufferContent(buf)); xmlBufferFree(buf); } xmlXPathFreeObject(xpathObj); } xmlXPathFreeContext(xpathCtx); } xmlFreeDoc(doc); } } int main() { xmlInitParser(); noproblem("", "//namespace::*"); xmlCleanupParser(); }