From 018e1ba581ec6f01f069a45ec4cf89f152b44d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 19 Mar 2025 15:41:36 +0100 Subject: remerge --- xsd/examples/cxx/tree/messaging/dom-serialize.cxx | 64 +++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 xsd/examples/cxx/tree/messaging/dom-serialize.cxx (limited to 'xsd/examples/cxx/tree/messaging/dom-serialize.cxx') diff --git a/xsd/examples/cxx/tree/messaging/dom-serialize.cxx b/xsd/examples/cxx/tree/messaging/dom-serialize.cxx new file mode 100644 index 0000000..dbf3370 --- /dev/null +++ b/xsd/examples/cxx/tree/messaging/dom-serialize.cxx @@ -0,0 +1,64 @@ +// file : examples/cxx/tree/messaging/dom-serialize.cxx +// copyright : not copyrighted - public domain + +#include "dom-serialize.hxx" + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +using namespace xercesc; +namespace xml = xsd::cxx::xml; +namespace tree = xsd::cxx::tree; + +void +serialize (std::ostream& os, + const xercesc::DOMDocument& doc, + const std::string& encoding) +{ + const XMLCh ls_id [] = {chLatin_L, chLatin_S, chNull}; + + // Get an implementation of the Load-Store (LS) interface. + // + DOMImplementation* impl ( + DOMImplementationRegistry::getDOMImplementation (ls_id)); + + tree::error_handler eh; + xml::dom::bits::error_handler_proxy ehp (eh); + + xml::dom::ostream_format_target oft (os); + + // Create a DOMSerializer. + // + xml::dom::auto_ptr writer ( + impl->createLSSerializer ()); + + DOMConfiguration* conf (writer->getDomConfig ()); + + // Set error handler. + // + conf->setParameter (XMLUni::fgDOMErrorHandler, &ehp); + + // Set some generally nice features. + // + conf->setParameter (XMLUni::fgDOMWRTDiscardDefaultContent, true); + conf->setParameter (XMLUni::fgDOMWRTFormatPrettyPrint, true); + conf->setParameter (XMLUni::fgDOMWRTXercesPrettyPrint, false); + + xml::dom::auto_ptr out (impl->createLSOutput ()); + out->setEncoding (xml::string (encoding).c_str ()); + out->setByteStream (&oft); + + writer->write (&doc, out.get ()); + + eh.throw_if_failed > (); +} -- cgit v1.2.3