mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: xml: Introduce virXMLFormatElementEmpty
Add a helper which will format an XML element with attributes and children, but compared to virXMLFormatElement it also formats an empty element if both buffers are empty. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com> Tested-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
6c7faa2720
commit
1ac21ab7ea
@ -3541,6 +3541,7 @@ virXMLBufferCreate;
|
|||||||
virXMLCheckIllegalChars;
|
virXMLCheckIllegalChars;
|
||||||
virXMLExtractNamespaceXML;
|
virXMLExtractNamespaceXML;
|
||||||
virXMLFormatElement;
|
virXMLFormatElement;
|
||||||
|
virXMLFormatElementEmpty;
|
||||||
virXMLNewNode;
|
virXMLNewNode;
|
||||||
virXMLNodeContentString;
|
virXMLNodeContentString;
|
||||||
virXMLNodeNameEqual;
|
virXMLNodeNameEqual;
|
||||||
|
@ -1631,6 +1631,32 @@ virXMLValidatorFree(virXMLValidator *validator)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* same as virXMLFormatElement but outputs an empty element if @attrBuf and
|
||||||
|
* @childBuf are both empty */
|
||||||
|
void
|
||||||
|
virXMLFormatElementEmpty(virBuffer *buf,
|
||||||
|
const char *name,
|
||||||
|
virBuffer *attrBuf,
|
||||||
|
virBuffer *childBuf)
|
||||||
|
{
|
||||||
|
virBufferAsprintf(buf, "<%s", name);
|
||||||
|
|
||||||
|
if (attrBuf && virBufferUse(attrBuf) > 0)
|
||||||
|
virBufferAddBuffer(buf, attrBuf);
|
||||||
|
|
||||||
|
if (childBuf && virBufferUse(childBuf) > 0) {
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
virBufferAddBuffer(buf, childBuf);
|
||||||
|
virBufferAsprintf(buf, "</%s>\n", name);
|
||||||
|
} else {
|
||||||
|
virBufferAddLit(buf, "/>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
virBufferFreeAndReset(attrBuf);
|
||||||
|
virBufferFreeAndReset(childBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXMLFormatElement
|
* virXMLFormatElement
|
||||||
* @buf: the parent buffer where the element will be placed
|
* @buf: the parent buffer where the element will be placed
|
||||||
@ -1655,21 +1681,7 @@ virXMLFormatElement(virBuffer *buf,
|
|||||||
(!childBuf || virBufferUse(childBuf) == 0))
|
(!childBuf || virBufferUse(childBuf) == 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<%s", name);
|
virXMLFormatElementEmpty(buf, name, attrBuf, childBuf);
|
||||||
|
|
||||||
if (attrBuf && virBufferUse(attrBuf) > 0)
|
|
||||||
virBufferAddBuffer(buf, attrBuf);
|
|
||||||
|
|
||||||
if (childBuf && virBufferUse(childBuf) > 0) {
|
|
||||||
virBufferAddLit(buf, ">\n");
|
|
||||||
virBufferAddBuffer(buf, childBuf);
|
|
||||||
virBufferAsprintf(buf, "</%s>\n", name);
|
|
||||||
} else {
|
|
||||||
virBufferAddLit(buf, "/>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
virBufferFreeAndReset(attrBuf);
|
|
||||||
virBufferFreeAndReset(childBuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -315,6 +315,13 @@ virXMLFormatElement(virBuffer *buf,
|
|||||||
virBuffer *attrBuf,
|
virBuffer *attrBuf,
|
||||||
virBuffer *childBuf);
|
virBuffer *childBuf);
|
||||||
|
|
||||||
|
void
|
||||||
|
virXMLFormatElementEmpty(virBuffer *buf,
|
||||||
|
const char *name,
|
||||||
|
virBuffer *attrBuf,
|
||||||
|
virBuffer *childBuf);
|
||||||
|
|
||||||
|
|
||||||
struct _virXPathContextNodeSave {
|
struct _virXPathContextNodeSave {
|
||||||
xmlXPathContextPtr ctxt;
|
xmlXPathContextPtr ctxt;
|
||||||
xmlNodePtr node;
|
xmlNodePtr node;
|
||||||
|
Loading…
Reference in New Issue
Block a user