summaryrefslogtreecommitdiffstats
path: root/include/tools/XmlWriter.hxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
commit267c6f2ac71f92999e969232431ba04678e7437e (patch)
tree358c9467650e1d0a1d7227a21dac2e3d08b622b2 /include/tools/XmlWriter.hxx
parentInitial commit. (diff)
downloadlibreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz
libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/tools/XmlWriter.hxx')
-rw-r--r--include/tools/XmlWriter.hxx70
1 files changed, 70 insertions, 0 deletions
diff --git a/include/tools/XmlWriter.hxx b/include/tools/XmlWriter.hxx
new file mode 100644
index 0000000000..400748611b
--- /dev/null
+++ b/include/tools/XmlWriter.hxx
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_TOOLS_XMLWRITER_HXX
+#define INCLUDED_TOOLS_XMLWRITER_HXX
+
+#include <tools/toolsdllapi.h>
+#include <rtl/string.hxx>
+#include <memory>
+#include <string_view>
+#include <vector>
+
+class SvStream;
+
+namespace tools
+{
+struct XmlWriterImpl;
+
+/**
+ * XmlWriter writes a XML to a SvStream. It uses libxml2 for writing but hides
+ * all the internal libxml2 workings and uses types that are native for LO
+ * development.
+ *
+ * The codepage used for XML is always "utf-8" and the output is indented by
+ * default so it is easier to read.
+ *
+ */
+class TOOLS_DLLPUBLIC XmlWriter final
+{
+private:
+ std::unique_ptr<XmlWriterImpl> mpImpl;
+
+public:
+ XmlWriter(SvStream* pStream);
+
+ ~XmlWriter();
+
+ bool startDocument(sal_Int32 nIndent = 2, bool bWriteXmlHeader = true);
+ void endDocument();
+
+ void startElement(const char* sName);
+ void startElement(const OString& sName);
+ void startElement(const OString& sPrefix, const OString& sName, const OString& sNamespaceUri);
+ void endElement();
+
+ void attribute(const char* sTagName, const OString& aValue);
+ void attribute(const OString& sTagName, const OString& aValue);
+ void attribute(const char* sTagName, std::u16string_view aValue);
+ void attribute(const char* sTagName, sal_Int32 aNumber);
+ void attributeDouble(const char* sTagName, double aNumber);
+ void attributeBase64(const char* sTagName, std::vector<sal_uInt8> const& rValueInBytes);
+ void attributeBase64(const char* sTagName, std::vector<char> const& rValueInBytes);
+
+ void content(const OString& sValue);
+ void content(std::u16string_view sValue);
+
+ void element(const char* sName);
+};
+
+} // end tools namespace
+
+#endif // INCLUDED_TOOLS_XMLWRITER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */