util: xml: introduce virXMLNamespaceRegister

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@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Ján Tomko 2019-08-20 22:14:13 +02:00
parent 56ecb33102
commit 37a11c3726
2 changed files with 22 additions and 0 deletions

View File

@ -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"
@ -1416,3 +1418,20 @@ virXMLNamespaceFormatNS(virBufferPtr buf,
{
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;
}

View File

@ -265,3 +265,6 @@ typedef virXMLNamespace *virXMLNamespacePtr;
void
virXMLNamespaceFormatNS(virBufferPtr buf,
virXMLNamespace const *ns);
int
virXMLNamespaceRegister(xmlXPathContextPtr ctxt,
virXMLNamespace const *ns);