mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
util: Add helper to convert libxml2 nodes to a string
This commit is contained in:
parent
e9cb66f14e
commit
be0f0c2292
@ -2092,6 +2092,7 @@ virUUIDParse;
|
|||||||
|
|
||||||
# util/virxml.h
|
# util/virxml.h
|
||||||
virXMLChildElementCount;
|
virXMLChildElementCount;
|
||||||
|
virXMLNodeToString;
|
||||||
virXMLParseHelper;
|
virXMLParseHelper;
|
||||||
virXMLPickShellSafeComment;
|
virXMLPickShellSafeComment;
|
||||||
virXMLPropString;
|
virXMLPropString;
|
||||||
|
@ -895,3 +895,36 @@ virXMLChildElementCount(xmlNodePtr node)
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virXMLNodeToString: convert an XML node ptr to an XML string
|
||||||
|
*
|
||||||
|
* Returns the XML string of the document or NULL on error.
|
||||||
|
* The caller has to free the string.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
virXMLNodeToString(xmlDocPtr doc,
|
||||||
|
xmlNodePtr node)
|
||||||
|
{
|
||||||
|
xmlBufferPtr xmlbuf = NULL;
|
||||||
|
char *ret = NULL;
|
||||||
|
|
||||||
|
if (!(xmlbuf = xmlBufferCreate())) {
|
||||||
|
virReportOOMError();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xmlNodeDump(xmlbuf, doc, node, 0, 1) == 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("failed to convert the XML node tree"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ignore_value(VIR_STRDUP(ret, (const char *)xmlBufferContent(xmlbuf)));
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
xmlBufferFree(xmlbuf);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -163,4 +163,6 @@ int virXMLSaveFile(const char *path,
|
|||||||
const char *warnCommand,
|
const char *warnCommand,
|
||||||
const char *xml);
|
const char *xml);
|
||||||
|
|
||||||
|
char *virXMLNodeToString(xmlDocPtr doc, xmlNodePtr node);
|
||||||
|
|
||||||
#endif /* __VIR_XML_H__ */
|
#endif /* __VIR_XML_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user