[xsd-users] serializing without pretty printing

Boris Kolpackov boris at codesynthesis.com
Wed Sep 19 14:28:48 EDT 2007


Hi Drago,

drago.krznaric at se.transport.bombardier.com <drago.krznaric at se.transport.bombardier.com> writes:

> Is there a simple way to get a more compact format? I guess I would like
> to tell the xerces' dom writer to set the XMLUni::
> fgDOMWRTFormatPrettyPrint
> feuture to false, but I don't see how to do that without changing the
> code of libxsd.

You can serialize the object model to a DOM document and then serialize
this document to XML without pretty-printing. For example:

#include <fstream>

#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/PlatformUtils.hpp>

#include <xsd/cxx/xml/dom/auto-ptr.hxx>

using namespace xercesc;
namespace xml = xsd::cxx::xml;

XMLPlatformUtils::Initialize ();

{
  xml::dom::auto_ptr<DOMDocument> doc = root (x, map);

  std::ofstream ofs ("out.xml");

  serialize (ofs, *doc);
}

XMLPlatformUtils::Terminate ();

In this example, root() is the serialization function corresponding
to your document root. serialize() is the function from Q3.2 in
C++/Tree Mapping FAQ:

http://wiki.codesynthesis.com/Tree/FAQ

You will need to change the following line in this function though:

writer->setFeature (XMLUni::fgDOMWRTFormatPrettyPrint, true);

For more information on serializing your object model to DOM, see
Section 4.7, "Serializing to DOM" in the C++/Tree Mapping User
Manual:

http://codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#4.7

Boris




More information about the xsd-users mailing list