Use virXMLParse's features to validate the top level element and fetch the XPath context. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/domain_conf.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 03f4b2fe33..bd882039e7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19080,29 +19080,19 @@ virDomainDefParse(const char *xmlStr, unsigned int flags) { g_autoptr(xmlDoc) xml = NULL; - virDomainDef *def = NULL; + g_autoptr(xmlXPathContext) ctxt = NULL; int keepBlanksDefault = xmlKeepBlanksDefault(0); - xmlNodePtr root; bool validate = flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; - if (!(xml = virXMLParse(filename, xmlStr, _("(domain_definition)"), - NULL, NULL, "domain.rng", validate))) - goto cleanup; + xml = virXMLParse(filename, xmlStr, _("(domain_definition)"), + "domain", &ctxt, "domain.rng", validate); - root = xmlDocGetRootElement(xml); - if (!virXMLNodeNameEqual(root, "domain")) { - virReportError(VIR_ERR_XML_ERROR, - _("unexpected root element <%s>, " - "expecting <domain>"), - root->name); - goto cleanup; - } + xmlKeepBlanksDefault(keepBlanksDefault); - def = virDomainDefParseNode(xml, root, xmlopt, parseOpaque, flags); + if (!xml) + return NULL; - cleanup: - xmlKeepBlanksDefault(keepBlanksDefault); - return def; + return virDomainDefParseNode(xml, ctxt->node, xmlopt, parseOpaque, flags); } virDomainDef * -- 2.37.3