mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
util: xml: Introduce virXMLNodeGetSubelementList
The new helper is similar to virXPathNodeSet list but for cases where we want to get subelements directly rather than using XPath. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
4aafa900ce
commit
dcd49d2cd6
@ -3709,6 +3709,7 @@ virXMLFormatMetadata;
|
||||
virXMLNewNode;
|
||||
virXMLNodeContentString;
|
||||
virXMLNodeGetSubelement;
|
||||
virXMLNodeGetSubelementList;
|
||||
virXMLNodeNameEqual;
|
||||
virXMLNodeSanitizeNamespaces;
|
||||
virXMLNodeToString;
|
||||
|
@ -899,6 +899,40 @@ virXMLNodeGetSubelement(xmlNodePtr node,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virXMLNodeGetSubelementList:
|
||||
* @node: node to get subelement of
|
||||
* @name: name of subelement to fetch (NULL to fetch all sub-elements)
|
||||
* @list: If non-NULL, filled with a list of pointers to the nodes. Caller is
|
||||
* responsible for freeing the list but not the members.
|
||||
*
|
||||
* Find and return a sub-elements node of @node named @name in a list.
|
||||
* Returns the number of subelements with @name
|
||||
*/
|
||||
size_t
|
||||
virXMLNodeGetSubelementList(xmlNodePtr node,
|
||||
const char *name,
|
||||
xmlNodePtr **list)
|
||||
{
|
||||
xmlNodePtr n;
|
||||
size_t nelems = 0;
|
||||
|
||||
for (n = node->children; n; n = n->next) {
|
||||
if (n->type == XML_ELEMENT_NODE) {
|
||||
if (name && !virXMLNodeNameEqual(n, name))
|
||||
continue;
|
||||
|
||||
if (list)
|
||||
VIR_APPEND_ELEMENT_COPY(*list, nelems, n);
|
||||
else
|
||||
nelems++;
|
||||
}
|
||||
}
|
||||
|
||||
return nelems;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virXPathNode:
|
||||
* @xpath: the XPath string to evaluate
|
||||
|
@ -77,6 +77,11 @@ xmlNodePtr
|
||||
virXMLNodeGetSubelement(xmlNodePtr node,
|
||||
const char *name);
|
||||
|
||||
size_t
|
||||
virXMLNodeGetSubelementList(xmlNodePtr node,
|
||||
const char *name,
|
||||
xmlNodePtr **list);
|
||||
|
||||
xmlNodePtr
|
||||
virXPathNode(const char *xpath,
|
||||
xmlXPathContextPtr ctxt);
|
||||
|
Loading…
Reference in New Issue
Block a user