[PATCH 20/21] Refactoring virDomainVideoDriverDefParseXML() to use XPath

Kristina Hanicova khanicov at redhat.com
Thu Apr 15 14:26:35 UTC 2021


Signed-off-by: Kristina Hanicova <khanicov at redhat.com>
---
 src/conf/domain_conf.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b9816c46ed..a5dce8a8af 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15049,25 +15049,16 @@ virDomainVideoResolutionDefParseXML(xmlNodePtr node)
 
 static virDomainVideoDriverDef *
 virDomainVideoDriverDefParseXML(xmlNodePtr node,
-                                xmlXPathContextPtr ctxt G_GNUC_UNUSED)
+                                xmlXPathContextPtr ctxt)
 {
-    xmlNodePtr cur;
     virDomainVideoDriverDef *def;
     int val;
     g_autofree char *vgaconf = NULL;
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
 
-    cur = node->children;
-    while (cur != NULL) {
-        if (cur->type == XML_ELEMENT_NODE) {
-            if (!vgaconf &&
-                virXMLNodeNameEqual(cur, "driver")) {
-                vgaconf = virXMLPropString(cur, "vgaconf");
-            }
-        }
-        cur = cur->next;
-    }
+    ctxt->node = node;
 
-    if (!vgaconf)
+    if (!(vgaconf = virXPathString("string(./driver/@vgaconf)", ctxt)))
         return NULL;
 
     def = g_new0(virDomainVideoDriverDef, 1);
-- 
2.30.2




More information about the libvir-list mailing list