mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 01:43:23 +00:00
util: xml: Introduce virXMLPropStringRequired
Similarly to virXMLPropString it extracts a string but reports an error similar to the newer virXMLProp helpers if the attribute is not present. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
4bab4de9b9
commit
65eaf58335
@ -3683,6 +3683,7 @@ virXMLPropEnum;
|
|||||||
virXMLPropEnumDefault;
|
virXMLPropEnumDefault;
|
||||||
virXMLPropInt;
|
virXMLPropInt;
|
||||||
virXMLPropString;
|
virXMLPropString;
|
||||||
|
virXMLPropStringRequired;
|
||||||
virXMLPropTristateBool;
|
virXMLPropTristateBool;
|
||||||
virXMLPropTristateBoolAllowDefault;
|
virXMLPropTristateBoolAllowDefault;
|
||||||
virXMLPropTristateSwitch;
|
virXMLPropTristateSwitch;
|
||||||
|
@ -455,6 +455,33 @@ virXMLPropString(xmlNodePtr node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virXMLPropStringRequired:
|
||||||
|
* @node: XML dom node pointer
|
||||||
|
* @name: Name of the property (attribute) to get
|
||||||
|
*
|
||||||
|
* Convenience function to return copy of an mandatoryu attribute value of an
|
||||||
|
* XML node.
|
||||||
|
*
|
||||||
|
* Returns the property (attribute) value as string or NULL and if the attribute
|
||||||
|
* is not present (libvirt error reported).
|
||||||
|
* The caller is responsible for freeing the returned buffer.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
virXMLPropStringRequired(xmlNodePtr node,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
char *ret = virXMLPropString(node, name);
|
||||||
|
|
||||||
|
if (!(*ret))
|
||||||
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
|
_("Missing required attribute '%s' in element '%s'"),
|
||||||
|
name, node->name);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXMLNodeContentString:
|
* virXMLNodeContentString:
|
||||||
* @node: XML dom node pointer
|
* @node: XML dom node pointer
|
||||||
|
@ -97,6 +97,10 @@ char *
|
|||||||
virXMLPropString(xmlNodePtr node,
|
virXMLPropString(xmlNodePtr node,
|
||||||
const char *name);
|
const char *name);
|
||||||
char *
|
char *
|
||||||
|
virXMLPropStringRequired(xmlNodePtr node,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
|
char *
|
||||||
virXMLNodeContentString(xmlNodePtr node);
|
virXMLNodeContentString(xmlNodePtr node);
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user