A wrapper around xmlXPathRegisterNs that will save us from having to include xpathInternals.h everywhere we want to use a custom namespace and open-coding the strings already contained in virXMLNamespace. Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx> --- src/util/virxml.c | 20 ++++++++++++++++++++ src/util/virxml.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 11b6031b09..84b824f432 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -24,6 +24,8 @@ #include <math.h> /* for isnan() */ #include <sys/stat.h> +#include <libxml/xpathInternals.h> + #include "virerror.h" #include "virxml.h" #include "virbuffer.h" @@ -1409,9 +1411,27 @@ virXPathContextNodeRestore(virXPathContextNodeSavePtr save) save->ctxt->node = save->node; } + void virXMLNamespaceFormatNS(virBufferPtr buf, virXMLNamespace const *ns) { virBufferAsprintf(buf, " xmlns:%s='%s'", ns->prefix, ns->href()); } + + +int +virXMLNamespaceRegister(xmlXPathContextPtr ctxt, + virXMLNamespace const *ns) +{ + if (xmlXPathRegisterNs(ctxt, + BAD_CAST ns->prefix, + BAD_CAST ns->href()) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to register xml namespace '%s'"), + ns->href()); + return -1; + } + + return 0; +} diff --git a/src/util/virxml.h b/src/util/virxml.h index bcc10647b5..dfa20b3edb 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -265,3 +265,6 @@ typedef virXMLNamespace *virXMLNamespacePtr; void virXMLNamespaceFormatNS(virBufferPtr buf, virXMLNamespace const *ns); +int +virXMLNamespaceRegister(xmlXPathContextPtr ctxt, + virXMLNamespace const *ns); -- 2.19.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list