/src/libreoffice/include/tools/XmlWriter.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <sal/config.h> |
13 | | |
14 | | #include <basegfx/numeric/ftools.hxx> |
15 | | #include <tools/toolsdllapi.h> |
16 | | #include <rtl/string.hxx> |
17 | | #include <memory> |
18 | | #include <string_view> |
19 | | #include <vector> |
20 | | #include <o3tl/concepts.hxx> |
21 | | |
22 | | class SvStream; |
23 | | struct _xmlTextWriter; |
24 | | typedef struct _xmlTextWriter* xmlTextWriterPtr; |
25 | | |
26 | | namespace tools |
27 | | { |
28 | | struct XmlWriterImpl; |
29 | | |
30 | | /** |
31 | | * XmlWriter writes a XML to a SvStream. It uses libxml2 for writing but hides |
32 | | * all the internal libxml2 workings and uses types that are native for LO |
33 | | * development. |
34 | | * |
35 | | * The codepage used for XML is always "utf-8" and the output is indented by |
36 | | * default so it is easier to read. |
37 | | * |
38 | | */ |
39 | | class TOOLS_DLLPUBLIC XmlWriter final |
40 | | { |
41 | | private: |
42 | | std::unique_ptr<XmlWriterImpl> mpImpl; |
43 | | |
44 | | public: |
45 | | XmlWriter(SvStream* pStream); |
46 | | XmlWriter(xmlTextWriterPtr pWriter); |
47 | | ~XmlWriter(); |
48 | | |
49 | | bool startDocument(sal_Int32 nIndent = 2, bool bWriteXmlHeader = true); |
50 | | void endDocument(); |
51 | | |
52 | | void startElement(const char* sName); |
53 | 0 | void startElement(const OString& sName) { startElement(sName.getStr()); } |
54 | | void startElement(const OString& sPrefix, const OString& sName, const OString& sNamespaceUri); |
55 | | void endElement(); |
56 | | |
57 | | void attribute(const char* sTagName, std::string_view aValue); |
58 | | void attribute(const char* sTagName, std::u16string_view aValue); |
59 | | void attribute(const char* sTagName, sal_Int64 aNumber); |
60 | | template <o3tl::integral T> void attribute(const char* sTagName, T aNumber) |
61 | 0 | { |
62 | 0 | return attribute(sTagName, static_cast<sal_Int64>(aNumber)); |
63 | 0 | } Unexecuted instantiation: _ZN5tools9XmlWriter9attributeITkNSt3__18integralEtEEvPKcT_ Unexecuted instantiation: _ZN5tools9XmlWriter9attributeITkNSt3__18integralEsEEvPKcT_ Unexecuted instantiation: _ZN5tools9XmlWriter9attributeITkNSt3__18integralEjEEvPKcT_ Unexecuted instantiation: _ZN5tools9XmlWriter9attributeITkNSt3__18integralEiEEvPKcT_ Unexecuted instantiation: _ZN5tools9XmlWriter9attributeITkNSt3__18integralEmEEvPKcT_ Unexecuted instantiation: _ZN5tools9XmlWriter9attributeITkNSt3__18integralEbEEvPKcT_ |
64 | | template <o3tl::floating_point T> void attribute(const char* sTagName, T aNumber) |
65 | 0 | { |
66 | 0 | return attribute(sTagName, basegfx::fround64(aNumber)); |
67 | 0 | } |
68 | | void attributeDouble(const char* sTagName, double aNumber); |
69 | | void attributeBase64(const char* sTagName, std::vector<sal_uInt8> const& rValueInBytes); |
70 | | void attributeBase64(const char* sTagName, std::vector<char> const& rValueInBytes); |
71 | | |
72 | | void content(std::string_view sValue); |
73 | | void content(std::u16string_view sValue); |
74 | | |
75 | | void element(const char* sName); |
76 | | }; |
77 | | |
78 | | } // end tools namespace |
79 | | |
80 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |