# xml.h
+virXMLChildElementCount;
virXMLParseHelper;
virXMLPropString;
virXMLSaveFile;
return virFileRewrite(path, S_IRUSR | S_IWUSR, virXMLRewriteFile, &data);
}
+
+/* Returns the number of children of node, or -1 on error. */
+long
+virXMLChildElementCount(xmlNodePtr node)
+{
+ long ret = 0;
+ xmlNodePtr cur = NULL;
+
+ /* xmlChildElementCount returns 0 on error, which isn't helpful;
+ * besides, it is not available in libxml2 2.6. */
+ if (!node || node->type != XML_ELEMENT_NODE)
+ return -1;
+ cur = node->children;
+ while (cur) {
+ if (cur->type == XML_ELEMENT_NODE)
+ ret++;
+ cur = cur->next;
+ }
+ return ret;
+}
xmlNodePtr **list);
char * virXMLPropString(xmlNodePtr node,
const char *name);
+long virXMLChildElementCount(xmlNodePtr node);
/* Internal function; prefer the macros below. */
xmlDocPtr virXMLParseHelper(int domcode,
bool found;
bool visited;
bool ret = false;
- unsigned long n1_child_size, n2_child_size, n1_iter;
+ long n1_child_size, n2_child_size, n1_iter;
virBitmapPtr bitmap;
if (!n1 && !n2)
attr = attr->next;
}
- n1_child_size = xmlChildElementCount(n1);
- n2_child_size = xmlChildElementCount(n2);
- if (n1_child_size < n2_child_size)
+ n1_child_size = virXMLChildElementCount(n1);
+ n2_child_size = virXMLChildElementCount(n2);
+ if (n1_child_size < 0 || n2_child_size < 0 ||
+ n1_child_size < n2_child_size)
return false;
if (n1_child_size == 0 && n2_child_size == 0)