1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef INCLUDED_TOOLS_XMLWRITER_HXX
11 #define INCLUDED_TOOLS_XMLWRITER_HXX
13 #include <sal/config.h>
15 #include <basegfx/numeric/ftools.hxx>
16 #include <tools/toolsdllapi.h>
17 #include <rtl/string.hxx>
19 #include <string_view>
29 * XmlWriter writes a XML to a SvStream. It uses libxml2 for writing but hides
30 * all the internal libxml2 workings and uses types that are native for LO
33 * The codepage used for XML is always "utf-8" and the output is indented by
34 * default so it is easier to read.
37 class TOOLS_DLLPUBLIC XmlWriter final
40 std::unique_ptr
<XmlWriterImpl
> mpImpl
;
43 XmlWriter(SvStream
* pStream
);
47 bool startDocument(sal_Int32 nIndent
= 2, bool bWriteXmlHeader
= true);
50 void startElement(const char* sName
);
51 void startElement(const OString
& sName
) { startElement(sName
.getStr()); }
52 void startElement(const OString
& sPrefix
, const OString
& sName
, const OString
& sNamespaceUri
);
55 void attribute(const char* sTagName
, const OString
& aValue
);
56 void attribute(const OString
& sTagName
, const OString
& aValue
)
58 attribute(sTagName
.getStr(), aValue
);
60 void attribute(const char* sTagName
, std::u16string_view aValue
);
61 void attribute(const char* sTagName
, sal_Int64 aNumber
);
63 requires
std::is_arithmetic_v
<T
> void attribute(const char* sTagName
, T aNumber
)
65 if constexpr (std::is_floating_point_v
<T
>)
66 return attribute(sTagName
, basegfx::fround64(aNumber
));
68 return attribute(sTagName
, static_cast<sal_Int64
>(aNumber
));
70 void attributeDouble(const char* sTagName
, double aNumber
);
71 void attributeBase64(const char* sTagName
, std::vector
<sal_uInt8
> const& rValueInBytes
);
72 void attributeBase64(const char* sTagName
, std::vector
<char> const& rValueInBytes
);
74 void content(const OString
& sValue
);
75 void content(std::u16string_view sValue
);
77 void element(const char* sName
);
80 } // end tools namespace
82 #endif // INCLUDED_TOOLS_XMLWRITER_HXX
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */