[xsde-users] How to serialize just a single element of an schema

Boris Kolpackov boris at codesynthesis.com
Wed Apr 13 09:20:58 EDT 2011


Hi Sebastian,

Ivan Le Lann <ivan.lelann at free.fr> writes:

> If I understand correctly what you're trying to do, you should use 
> "--root-element my_non_root_element" command line option.

If this is a global element, then, yes, that's probably the easiest
way to do it.

If, however, the element is local (that is, you want to serialize
an instance of some complex type), then this approach won't work.
What you need to do is generate a serializer aggregate for such
a type using the --root-type option.

As an example, let's say we want to serialize an instance of the
'author' type from the 'library' example (cxx/hybrid/library/).
When compiling 'library.xsd' we add "--root-type author":

xsde cxx-hybrid --generate-serializer --generate-aggregate \
  --root-type author library.xsd

Then our code looks very similar to the version that serializes
the root element:

    author_saggr author_s;

    xml_schema::document_simpl doc_s (
      author_s.root_serializer (),      
      "author"); // Root element name.

    author_s.pre (*a);
    doc_s.serialize (cout, xml_schema::document_simpl::pretty_print);
    author_s.post ();

Boris



More information about the xsde-users mailing list