Tests: Consider lttng mi namespace in test_mi
[lttng-tools.git] / tests / regression / tools / mi / extract_xml.c
index 7edf1716eb979ad07da7ba35f48d8edddaa3b660..ddf8c16773331b9786b2018c4cbf2d7fb5a651e5 100644 (file)
@@ -43,6 +43,7 @@
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
 #include <libxml/xpathInternals.h>
+#include <common/defaults.h>
 
 #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) {
This page took 0.0235 seconds and 4 git commands to generate.