diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-07-04 17:18:43 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-07-06 18:26:36 +0200 |
commit | 72aa159a6fce92f47a56a8de8c7f8260577dd936 (patch) | |
tree | 2212bada2a0dc8a7fce00b5b27e159aff99c6adb /tools/source/xml | |
parent | 6db3aeb6e698b07d2fb4985a0c529358b7323f55 (diff) |
XmlWriter: support namespaces, writing of base64 attribute
Change-Id: I3c1d885d239178b46578123fd83d3aa1d7ccd023
Reviewed-on: https://gerrit.libreoffice.org/56971
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'tools/source/xml')
-rw-r--r-- | tools/source/xml/XmlWriter.cxx | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/tools/source/xml/XmlWriter.cxx b/tools/source/xml/XmlWriter.cxx index ba2c3936f51b..8895e92064db 100644 --- a/tools/source/xml/XmlWriter.cxx +++ b/tools/source/xml/XmlWriter.cxx @@ -54,14 +54,14 @@ XmlWriter::~XmlWriter() endDocument(); } -bool XmlWriter::startDocument() +bool XmlWriter::startDocument(sal_Int32 nIndent) { xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(funcWriteCallback, funcCloseCallback, mpImpl->mpStream, nullptr); mpImpl->mpWriter = xmlNewTextWriter(xmlOutBuffer); if (mpImpl->mpWriter == nullptr) return false; - xmlTextWriterSetIndent(mpImpl->mpWriter, 1); + xmlTextWriterSetIndent(mpImpl->mpWriter, nIndent); xmlTextWriterStartDocument(mpImpl->mpWriter, nullptr, "UTF-8", nullptr); return true; } @@ -73,6 +73,26 @@ void XmlWriter::endDocument() mpImpl->mpWriter = nullptr; } +void XmlWriter::startElement(const OString& sPrefix, const OString& sName, + const OString& sNamespaceUri) +{ + xmlChar* xmlName = xmlCharStrdup(sName.getStr()); + xmlChar* xmlPrefix = nullptr; + xmlChar* xmlNamespaceUri = nullptr; + if (!sPrefix.isEmpty()) + xmlPrefix = xmlCharStrdup(sPrefix.getStr()); + if (!sNamespaceUri.isEmpty()) + xmlNamespaceUri = xmlCharStrdup(sNamespaceUri.getStr()); + + xmlTextWriterStartElementNS(mpImpl->mpWriter, xmlPrefix, xmlName, xmlNamespaceUri); + + xmlFree(xmlName); + if (!sPrefix.isEmpty()) + xmlFree(xmlPrefix); + if (!sNamespaceUri.isEmpty()) + xmlFree(xmlNamespaceUri); +} + void XmlWriter::startElement(const OString& sName) { xmlChar* xmlName = xmlCharStrdup(sName.getStr()); @@ -82,6 +102,21 @@ void XmlWriter::startElement(const OString& sName) void XmlWriter::endElement() { xmlTextWriterEndElement(mpImpl->mpWriter); } +void XmlWriter::attributeBase64(const OString& rsName, std::vector<sal_uInt8> const& rValueInBytes) +{ + std::vector<char> aSignedBytes(rValueInBytes.begin(), rValueInBytes.end()); + attributeBase64(rsName, aSignedBytes); +} + +void XmlWriter::attributeBase64(const OString& rsName, std::vector<char> const& rValueInBytes) +{ + xmlChar* xmlName = xmlCharStrdup(rsName.getStr()); + xmlTextWriterStartAttribute(mpImpl->mpWriter, xmlName); + xmlTextWriterWriteBase64(mpImpl->mpWriter, rValueInBytes.data(), 0, rValueInBytes.size()); + xmlTextWriterEndAttribute(mpImpl->mpWriter); + xmlFree(xmlName); +} + void XmlWriter::attribute(const OString& name, const OString& value) { xmlChar* xmlName = xmlCharStrdup(name.getStr()); |