We are formatting <enum/> element and its children using virBufferAddLit(), virBufferAsprintf(), virBufferAdjustIndent(), etc. Well, we can avoid that when switching to virXMLFormatElement(). Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_capabilities.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index 4e412c0fd8..b464298003 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -269,18 +269,14 @@ virDomainCapsEnumFormat(virBuffer *buf, const char *capsEnumName, virDomainCapsValToStr valToStr) { + virBuffer attrBuf = VIR_BUFFER_INITIALIZER; + virBuffer childBuf = VIR_BUFFER_INIT_CHILD(buf); size_t i; if (!capsEnum->report) return 0; - virBufferAsprintf(buf, "<enum name='%s'", capsEnumName); - if (!capsEnum->values) { - virBufferAddLit(buf, "/>\n"); - return 0; - } - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); + virBufferAsprintf(&attrBuf, " name='%s'", capsEnumName); for (i = 0; i < sizeof(capsEnum->values) * CHAR_BIT; i++) { const char *val; @@ -289,11 +285,10 @@ virDomainCapsEnumFormat(virBuffer *buf, continue; if ((val = (valToStr)(i))) - virBufferAsprintf(buf, "<value>%s</value>\n", val); + virBufferAsprintf(&childBuf, "<value>%s</value>\n", val); } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "</enum>\n"); + virXMLFormatElement(buf, "enum", &attrBuf, &childBuf); return 0; } -- 2.38.2