[Libvirt-cim] [PATCH V2 36/48] Fix xml generation algorithm in system_xml()

Xu Wang cngesaint at gmail.com
Mon Oct 28 02:46:05 UTC 2013


Signed-off-by: Xu Wang <gesaint at linux.vnet.ibm.com>
---
 libxkutil/xmlgen.c |  120 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 88 insertions(+), 32 deletions(-)

diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 6c4b832..91ac44a 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -1869,56 +1869,112 @@ static const char *input_xml(xmlNodePtr root, struct domain *dominfo)
 
 static char *system_xml(xmlNodePtr root, struct domain *domain)
 {
-        xmlNodePtr tmp;
-
-        tmp = xmlNewChild(root, NULL, BAD_CAST "name", BAD_CAST domain->name);
-        if (tmp == NULL)
+        CU_DEBUG("Enter system_xml()");
+
+        domain->others = add_node_to_others(domain->others,
+                                            0,
+                                            "name",
+                                            domain->name,
+                                            TYPE_NODE,
+                                            0,
+                                            "domain");
+
+        if (domain->others == NULL) {
+                CU_DEBUG("add node <name> failed.");
                 return XML_ERROR;
+        }
 
         if (domain->bootloader) {
-                tmp = xmlNewChild(root,
-                                  NULL,
-                                  BAD_CAST "bootloader",
-                                  BAD_CAST domain->bootloader);
-                if (tmp == NULL)
+                domain->others = add_node_to_others(domain->others,
+                                                    0,
+                                                    "bootloader",
+                                                    domain->bootloader,
+                                                    TYPE_NODE,
+                                                    0,
+                                                    "domain");
+
+                if (domain->others == NULL) {
+                        CU_DEBUG("add node <bootloader> failed.");
                         return XML_ERROR;
+                }
         }
 
         if (domain->bootloader_args) {
-                tmp = xmlNewChild(root,
-                                  NULL,
-                                  BAD_CAST "bootloader_args",
-                                  BAD_CAST domain->bootloader_args);
-                if (tmp == NULL)
+                domain->others = add_node_to_others(domain->others,
+                                                    0,
+                                                    "bootloader_args",
+                                                    domain->bootloader_args,
+                                                    TYPE_NODE,
+                                                    0,
+                                                    "domain");
+
+                if (domain->others == NULL) {
+                        CU_DEBUG("add node <bootloader_args> failed.");
                         return XML_ERROR;
+                }
         }
 
-        tmp = xmlNewChild(root,
-                          NULL,
-                          BAD_CAST "on_poweroff",
-                          BAD_CAST vssd_recovery_action_str(domain->on_poweroff));
-        if (tmp == NULL)
+        domain->others = add_node_to_others(domain->others,
+                                            0,
+                                            "on_poweroff",
+                                            vssd_recovery_action_str(domain->on_poweroff),
+                                            TYPE_NODE,
+                                            0,
+                                            "domain");
+
+        if (domain->others == NULL) {
+                CU_DEBUG("add node <on_poweroff> failed.");
                 return XML_ERROR;
+        }
 
-        tmp = xmlNewChild(root,
-                          NULL,
-                          BAD_CAST "on_crash",
-                          BAD_CAST vssd_recovery_action_str(domain->on_crash));
-        if (tmp == NULL)
+        domain->others = add_node_to_others(domain->others,
+                                            0,
+                                            "on_crash",
+                                            vssd_recovery_action_str(domain->on_crash),
+                                            TYPE_NODE,
+                                            0,
+                                            "domain");
+
+        if (domain->others == NULL) {
+                CU_DEBUG("add node <on_crash> failed.");
                 return XML_ERROR;
+        }
 
-        tmp = xmlNewChild(root,
-                          NULL,
-                          BAD_CAST "uuid",
-                          BAD_CAST domain->uuid);
-        if (tmp == NULL)
+        domain->others = add_node_to_others(domain->others,
+                                            0,
+                                            "uuid",
+                                            domain->uuid,
+                                            TYPE_NODE,
+                                            0,
+                                            "domain");
+
+        if (domain->others == NULL) {
+                CU_DEBUG("add node <uuid> failed.");
                 return XML_ERROR;
+        }
+
 
         if (domain->clock != NULL) {
-                tmp = xmlNewChild(root, NULL, BAD_CAST "clock", NULL);
-                if (tmp == NULL)
+                domain->others = add_node_to_others(domain->others,
+                                                    0,
+                                                    "clock",
+                                                    NULL,
+                                                    TYPE_NODE,
+                                                    0,
+                                                    "domain");
+
+                if (domain->others == NULL) {
+                        CU_DEBUG("add node <clock> failed.");
                         return XML_ERROR;
-                xmlNewProp(tmp, BAD_CAST "offset", BAD_CAST domain->clock);
+                }
+
+                domain->others = add_node_to_others(domain->others,
+                                                    0,
+                                                    "offset",
+                                                    domain->clock,
+                                                    TYPE_PROP,
+                                                    0,
+                                                    "clock");
         }
 
         return NULL;
-- 
1.7.1




More information about the Libvirt-cim mailing list