X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Fregression%2Ftools%2Fmi%2Fextract_xml.c;h=ddf8c16773331b9786b2018c4cbf2d7fb5a651e5;hp=7edf1716eb979ad07da7ba35f48d8edddaa3b660;hb=41af1adf5100627c2e11565e7d9e4b9c5a8b9fac;hpb=a23cb78a01517b0a185df90fe173278e431b93e0 diff --git a/tests/regression/tools/mi/extract_xml.c b/tests/regression/tools/mi/extract_xml.c index 7edf1716e..ddf8c1677 100644 --- a/tests/regression/tools/mi/extract_xml.c +++ b/tests/regression/tools/mi/extract_xml.c @@ -43,6 +43,7 @@ #include #include #include +#include #if defined(LIBXML_XPATH_ENABLED) @@ -135,6 +136,31 @@ end: return ret; } +static int register_lttng_namespace(xmlXPathContextPtr xpathCtx) +{ + int ret; + xmlChar *prefix; + xmlChar *ns = NULL; + + prefix = xmlCharStrdup("lttng"); + if (!prefix) { + ret = -1; + goto end; + } + + ns = xmlCharStrdup(DEFAULT_LTTNG_MI_NAMESPACE); + if (!ns) { + ret = -1; + goto end; + } + + ret = xmlXPathRegisterNs(xpathCtx, prefix, ns); + xmlFree(prefix); +end: + xmlFree(ns); + return ret; +} + /* * Extract element corresponding to xpath * xml_path The path to the xml file @@ -147,6 +173,7 @@ end: */ static int extract_xpath(const char *xml_path, const xmlChar *xpath) { + int ret; xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtx = NULL; xmlXPathObjectPtr xpathObj = NULL; @@ -169,6 +196,15 @@ static int extract_xpath(const char *xml_path, const xmlChar *xpath) return -1; } + /* Register the LTTng MI namespace */ + ret = register_lttng_namespace(xpathCtx); + if (ret) { + fprintf(stderr, "ERR: Could not register lttng namespace\n"); + xmlXPathFreeContext(xpathCtx); + xmlFreeDoc(doc); + return -1; + } + /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression(xpath, xpathCtx); if (!xpathObj) {