mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
util: xml: Introduce virXMLNodeGetSubelement
Introduce a simple helper fetching a sub-element node by name. This is meant as a simple replacement for either open-coded versions of this or use of XPath for this trivial lookup. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
a5911fd808
commit
1a136152e6
@ -3671,6 +3671,7 @@ virXMLFormatElementInternal;
|
||||
virXMLFormatMetadata;
|
||||
virXMLNewNode;
|
||||
virXMLNodeContentString;
|
||||
virXMLNodeGetSubelement;
|
||||
virXMLNodeNameEqual;
|
||||
virXMLNodeSanitizeNamespaces;
|
||||
virXMLNodeToString;
|
||||
|
@ -849,6 +849,29 @@ virXPathBoolean(const char *xpath,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virXMLNodeGetSubelement:
|
||||
* @node: node to get subelement of
|
||||
* @name: name of subelement to fetch
|
||||
*
|
||||
* Find and return a sub-element node of @node named @name.
|
||||
*/
|
||||
xmlNodePtr
|
||||
virXMLNodeGetSubelement(xmlNodePtr node,
|
||||
const char *name)
|
||||
{
|
||||
xmlNodePtr n;
|
||||
|
||||
for (n = node->children; n; n = n->next) {
|
||||
if (n->type == XML_ELEMENT_NODE &&
|
||||
virXMLNodeNameEqual(n, name))
|
||||
return n;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virXPathNode:
|
||||
* @xpath: the XPath string to evaluate
|
||||
|
@ -72,6 +72,11 @@ int
|
||||
virXPathLongLong(const char *xpath,
|
||||
xmlXPathContextPtr ctxt,
|
||||
long long *value);
|
||||
|
||||
xmlNodePtr
|
||||
virXMLNodeGetSubelement(xmlNodePtr node,
|
||||
const char *name);
|
||||
|
||||
xmlNodePtr
|
||||
virXPathNode(const char *xpath,
|
||||
xmlXPathContextPtr ctxt);
|
||||
|
Loading…
Reference in New Issue
Block a user