g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
- if (!(xml = virXMLParseStringCtxt(xmlStr, _("(disk_definition)"), &ctxt)))
+ if (!(xml = virXMLParseStringCtxtRoot(xmlStr, _("(disk_definition)"), "disk", &ctxt)))
return NULL;
- if (!virXMLNodeNameEqual(ctxt->node, "disk")) {
- virReportError(VIR_ERR_XML_ERROR,
- _("expecting root element of 'disk', not '%s'"),
- ctxt->node->name);
- return NULL;
- }
-
return virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt, flags);
}
int pool_type)
{
g_autoptr(xmlDoc) doc = NULL;
- xmlNodePtr node = NULL;
g_autoptr(xmlXPathContext) xpath_ctxt = NULL;
g_autoptr(virStoragePoolSource) def = NULL;
- if (!(doc = virXMLParseStringCtxt(srcSpec,
- _("(storage_source_specification)"),
- &xpath_ctxt)))
+ if (!(doc = virXMLParseStringCtxtRoot(srcSpec,
+ _("(storage_source_specification)"),
+ "source",
+ &xpath_ctxt)))
return NULL;
def = g_new0(virStoragePoolSource, 1);
- if (!(node = virXPathNode("/source", xpath_ctxt))) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("root element was not source"));
- return NULL;
- }
-
if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type,
- node) < 0)
+ xpath_ctxt->node) < 0)
return NULL;
return g_steal_pointer(&def);
#define virXMLParseStringCtxt(xmlStr, url, pctxt) \
virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, NULL, pctxt)
+/* virXMLParseStringCtxtRoot is same as above, except it also validates root node name */
+#define virXMLParseStringCtxtRoot(xmlStr, url, rootnode, pctxt) \
+ virXMLParseHelper(VIR_FROM_THIS, NULL, xmlStr, url, rootnode, pctxt)
+
/**
* virXMLParseFileCtxt:
* @filename: file to parse