[xsd-users] xsdcxx-musicxml

Boris Kolpackov boris at codesynthesis.com
Wed Dec 10 08:03:50 EST 2014


Hi Mario,

Mario Lang <mlang at delysid.org> writes:

>  * How do I add a DOCTYPE to a serialized document?  Valid MusicXML documents
>    sort of require a DTD to be stated.  Is there some way to tell the
>    xsdcxx serializer (a bit like the properties class) that I want a !DOCTYPE to be
>    generated as well?  Or do I serialize to a DOM document and somehow
>    add the DOCTYPE later

The way to do this is to create the DOM document with DOCTYPE yourself,
then serialize the object model into it, and, finally, serialize the
DOM document to XML.

The Wiki has some sample code in the FAQ for how to to this. For the
DOCTYPE part, look into the DOMImplementation class:

https://xerces.apache.org/xerces-c/apiDocs-3/classDOMImplementation.html


> While there is at least one subelement which can be a sequence as well
> (dot), all others are just optionals.

I took a look at the schema and the generated code. The first element
in the generated code that I see that is a sequence is 'tie'. Looking
at the schema:

<xs:element name="tie" type="tie" minOccurs="0" maxOccurs="2"/>

The next is 'dot':

<xs:element name="dot" type="empty-placement" minOccurs="0" maxOccurs="unbounded">

Then 'beam':

<xs:element name="beam" type="beam" minOccurs="0" maxOccurs="8"/>

Then 'notation':

<xs:element name="notations" type="notations" minOccurs="0" maxOccurs="unbounded"/>

I stopped here.


> Now, to fix this, I have to
>    enable content_order for this element, which vastly complicates
>    client code for absolutely no reason.  I basically have to find a way
>    to re-implement accessors such that content_order is handled.
> 
>    1. Do you think we might be able to work on getting xsdcxx to DTRT
>       for this particular element type?  (The relevant XSD snippet is
>       below.)

I am not sure what DTRT is in this case. To me it seems XSD correctly
detects optional/sequence cardinalities (for the flattaned model that
it implements).


> 
>    2. If no, I will have to manually fix this up.  Either by writing all
>       the content_order handling code required for this class (quite
>       tedious), or, by manually implementing the part of the
>       serialization code that is broken.  Second option is
>       easier to do.  Is there actually a mechanism in xsdcxx to
>       allow for manual override of particular implementations of
>       the .cxx file?

See the C++/Tree Mapping Customization Guide:

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

As well as the examples in the examples/cxx/tree/custom/ directory.

Boris



More information about the xsd-users mailing list