tdf#167689: Calc: check if XML declaration exists

when exporting xl/xmlMaps.xml

follow-up for https://gerrit.libreoffice.org/c/core/+/189044
(657f0112b5)

Signed-off-by: Bayram Çiçek <bayram.cicek@collabora.com>
Change-Id: Iac5e94774632d74f1b99a32aaa56514396b10792
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189989
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
This commit is contained in:
Bayram Çiçek
2025-08-21 13:55:54 +02:00
parent 1f9fa0dd5b
commit 4199a5a630
+5 -2
View File
@@ -1292,8 +1292,11 @@ void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
/* we should remove <?xml version="1.0" encoding="UTF-8"?>
XML declaration from the string as rStrm.PushStream() already adds it. */
sal_uInt32 nXmlDeclarationLocation = sXmlMapsContent.find(">");
sXmlMapsContent = sXmlMapsContent.substr(nXmlDeclarationLocation + 1);
const std::size_t nXmlDeclarationLocation = sXmlMapsContent.find("?>");
// but there may not be an XML declaration, we should also check that.
if (nXmlDeclarationLocation != std::string::npos)
sXmlMapsContent = sXmlMapsContent.substr(nXmlDeclarationLocation + 2);
// write contents into xl/xmlMaps.xml
rStrm.GetCurrentStream()->write(sXmlMapsContent);