[4/8] util: xml: add virXMLPropertyCount

Message ID 728ba278f42eb1b900ac43f05d388d31e88c932f.1457454944.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson March 8, 2016, 4:36 p.m.
Returns an integer count of the number of XML properties an element
has. Will be used in future patches.
---
 src/util/virxml.c | 17 +++++++++++++++++
 src/util/virxml.h |  1 +
 2 files changed, 18 insertions(+)

-- 
2.5.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Patch hide | download patch | download mbox

diff --git a/src/util/virxml.c b/src/util/virxml.c
index 489bad8..86c021c 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -890,6 +890,23 @@  virXMLChildElementCount(xmlNodePtr node)
     return ret;
 }
 
+/* Returns the number of node's properties, or -1 on error.  */
+long
+virXMLPropertyCount(xmlNodePtr node)
+{
+    long ret = 0;
+    xmlAttrPtr cur = NULL;
+
+    if (!node || node->type != XML_ELEMENT_NODE)
+        return -1;
+    cur = node->properties;
+    while (cur) {
+        ret++;
+        cur = cur->next;
+    }
+    return ret;
+}
+
 
 /**
  * virXMLNodeToString: convert an XML node ptr to an XML string
diff --git a/src/util/virxml.h b/src/util/virxml.h
index b94de74..5cf082e 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -72,6 +72,7 @@  int              virXPathNodeSet(const char *xpath,
 char *          virXMLPropString(xmlNodePtr node,
                                  const char *name);
 long     virXMLChildElementCount(xmlNodePtr node);
+long     virXMLPropertyCount(xmlNodePtr node);
 
 /* Internal function; prefer the macros below.  */
 xmlDocPtr      virXMLParseHelper(int domcode,