13#include <libxml/xmlwriter.h>
19int funcWriteCallback(
void* pContext,
const char* sBuffer,
int nLen)
22 return static_cast<int>(pStream->
WriteBytes(sBuffer, nLen));
25int funcCloseCallback(
void* pContext)
61 mpImpl->mbWriteXmlHeader = bWriteXmlHeader;
62 xmlCharEncodingHandlerPtr pEncodingHandler = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8);
63 xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(funcWriteCallback, funcCloseCallback,
64 mpImpl->mpStream, pEncodingHandler);
65 mpImpl->mpWriter = xmlNewTextWriter(xmlOutBuffer);
66 if (
mpImpl->mpWriter ==
nullptr)
68 xmlTextWriterSetIndent(
mpImpl->mpWriter, nIndent);
69 if (
mpImpl->mbWriteXmlHeader)
70 (void)xmlTextWriterStartDocument(
mpImpl->mpWriter,
nullptr,
"UTF-8",
nullptr);
76 if (
mpImpl->mbWriteXmlHeader)
77 (void)xmlTextWriterEndDocument(
mpImpl->mpWriter);
78 xmlFreeTextWriter(
mpImpl->mpWriter);
79 mpImpl->mpWriter =
nullptr;
83 const OString& sNamespaceUri)
85 xmlChar* xmlName = BAD_CAST(
sName.getStr());
86 xmlChar* xmlPrefix =
nullptr;
87 xmlChar* xmlNamespaceUri =
nullptr;
89 xmlPrefix = BAD_CAST(
sPrefix.getStr());
90 if (!sNamespaceUri.isEmpty())
91 xmlNamespaceUri = BAD_CAST(sNamespaceUri.getStr());
93 (void)xmlTextWriterStartElementNS(
mpImpl->mpWriter, xmlPrefix, xmlName, xmlNamespaceUri);
98 xmlChar* xmlName = BAD_CAST(
pName);
99 (void)xmlTextWriterStartElement(
mpImpl->mpWriter, xmlName);
104 xmlChar* xmlName = BAD_CAST(rName.getStr());
105 (void)xmlTextWriterStartElement(
mpImpl->mpWriter, xmlName);
112 std::vector<char> aSignedBytes(rValueInBytes.begin(), rValueInBytes.end());
118 xmlChar* xmlName = BAD_CAST(
pName);
119 (void)xmlTextWriterStartAttribute(
mpImpl->mpWriter, xmlName);
120 (void)xmlTextWriterWriteBase64(
mpImpl->mpWriter, rValueInBytes.data(), 0, rValueInBytes.size());
121 (void)xmlTextWriterEndAttribute(
mpImpl->mpWriter);
126 xmlChar* xmlName = BAD_CAST(
name);
127 xmlChar* xmlValue = BAD_CAST(
value.getStr());
128 (void)xmlTextWriterWriteAttribute(
mpImpl->mpWriter, xmlName, xmlValue);
133 xmlChar* xmlName = BAD_CAST(
name.getStr());
134 xmlChar* xmlValue = BAD_CAST(
value.getStr());
135 (void)xmlTextWriterWriteAttribute(
mpImpl->mpWriter, xmlName, xmlValue);
155 xmlChar* xmlValue = BAD_CAST(sValue.getStr());
156 (void)xmlTextWriterWriteString(
mpImpl->mpWriter, xmlValue);
std::size_t WriteBytes(const void *pData, std::size_t nSize)
void Flush()
Call FlushBuffer() and then call flush on the underlying OS stream.
struct _xmlTextWriter * xmlTextWriterPtr
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)