From 6cb711645b8d8f3cee0d3454e193cc7bf1cad305 Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Sat, 16 Nov 2024 17:41:45 +0100 Subject: docx: export empty GrabBag elements as self-closing xml tags Although and are syntactically equivalent, we got a report that some 3rd party tool could not process a docx file produced by LibreOffice. In styles.xml there was instead of This patch is meant to fix this, to mimic what Word does anyway. Change-Id: Iea409981d2a2eac40c460bdae4d3dc7e8b0c33ae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176680 Reviewed-by: Andras Timar Tested-by: Jenkins --- sw/source/filter/ww8/docxattributeoutput.cxx | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'sw/source') diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 294651fbeb22..f3b5ce705242 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -3518,21 +3518,28 @@ void lclProcessRecursiveGrabBag(sal_Int32 aElementId, const css::uno::Sequenceadd(*aSubElementId, aValue); } - pSerializer->startElement(aElementId, pAttributes); - - for (const auto& rElement : rElements) + if (rElements.size() == 0) + { + pSerializer->singleElement(aElementId, pAttributes); + } + else { - css::uno::Sequence aSumElements; + pSerializer->startElement(aElementId, pAttributes); - std::optional aSubElementId = lclGetElementIdForName(rElement.Name); - if(aSubElementId) + for (const auto& rElement : rElements) { - rElement.Value >>= aSumElements; - lclProcessRecursiveGrabBag(*aSubElementId, aSumElements, pSerializer); + css::uno::Sequence aSumElements; + + std::optional aSubElementId = lclGetElementIdForName(rElement.Name); + if(aSubElementId) + { + rElement.Value >>= aSumElements; + lclProcessRecursiveGrabBag(*aSubElementId, aSumElements, pSerializer); + } } - } - pSerializer->endElement(aElementId); + pSerializer->endElement(aElementId); + } } constexpr auto constTransformationToTokenId = frozen::make_unordered_map({ -- cgit