From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- examples/cxx/tree/messaging/dom-serialize.cxx | 89 +++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 examples/cxx/tree/messaging/dom-serialize.cxx (limited to 'examples/cxx/tree/messaging/dom-serialize.cxx') diff --git a/examples/cxx/tree/messaging/dom-serialize.cxx b/examples/cxx/tree/messaging/dom-serialize.cxx new file mode 100644 index 0000000..c0f4311 --- /dev/null +++ b/examples/cxx/tree/messaging/dom-serialize.cxx @@ -0,0 +1,89 @@ +// file : examples/cxx/tree/messaging/dom-serialize.cxx +// author : Boris Kolpackov +// 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); + +#if _XERCES_VERSION >= 30000 + + // 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); + + xml::dom::auto_ptr out (impl->createLSOutput ()); + out->setEncoding (xml::string (encoding).c_str ()); + out->setByteStream (&oft); + + writer->write (&doc, out.get ()); + +#else + + // Create a DOMWriter. + // + xml::dom::auto_ptr writer (impl->createDOMWriter ()); + + // Set error handler. + // + writer->setErrorHandler (&ehp); + + // Set encoding. + // + writer->setEncoding(xml::string (encoding).c_str ()); + + // Set some generally nice features. + // + writer->setFeature (XMLUni::fgDOMWRTDiscardDefaultContent, true); + writer->setFeature (XMLUni::fgDOMWRTFormatPrettyPrint, true); + + writer->writeNode (&oft, doc); + +#endif + + eh.throw_if_failed > (); +} -- cgit v1.1