[xsd-users] Preserving element order in MusicXML?

Mario Lang mlang at delysid.org
Wed May 28 09:44:59 EDT 2008


Hi.

I just stumbled across xsdcxx (very very cool!) since I am working
on MusicXML software.  I've got a xsd file by using trang to
convert from the DTD[1], and applied a little bit of hand editing.
So far, so good.  I ym using cxx-tree and My test program kind of works.
Now I added serialisation and noticed that the output XML file
looses element order, which is dramatic for MusicXML files.

The problem is as follows: MusicXML defined a complexType (music-data)
which basically behaves like HTML body.  There are a number of elements
that can occur inside music-data (<attributes>, <note>, <backward>...) but the
exact ordering of the elements should not be forced in the Schema.
Every element can occur either 0 times or any number of times.
And the ordering of elements needs to be preserved.

I.e.  if I have:

<measure>
  <attributes>...</attributess>
  <note>...</note><note>...</note>
  <note>...</note><note>...</note>
  <backup>...</backup>
  <attributes>...</attributes>
  <note>...</note>
</measure>

would be a valid MusicXML snippet.

Currently, after xsdcxx serialisation of the above snippet, I get
sonmething like:

<measure>
  <note>...</note><note>...</note>
  <note>...</note><note>...</note>
  <note>...</note>
  <backup>...</backup>
  <attributes>...</attributess>
  <attributes>...</attributes>
</measure>

which is completely wrong in MusicXML context, since the elements 
can be thought of like statements in a procedural program, they
depend on the order of things being preserved.

I've read through the XML Schema specification documents on the
web, tried a few variants of <xsd:choice> inside <xsd:sequence> with
various minOccurs and maxOccurs values, but nothing
seems to instruct xsdcxx to generate a model that correctly
serialized the data back out to XML without destroying element order.

I am beginning to suspect that this is actually a XML Schema limitation
or a limitation in xsdcxx that I am hitting here.

This is what I tried (I tried various other variants as well):
<xs:complexType name="music-data">
  <xs:sequence>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="note" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="backup" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="forward" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="direction" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="attributes" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="harmony" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="figured-bass" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="print" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="sound" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="barline" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="grouping" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="link" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element ref="bookmark" minOccurs="0" maxOccurs="unbounded"/>
    </xs:choice>
  </xs:sequence>
</xs:complexType>
<xs:element name="measure" type="music-data"/>


Is it possible to express a schema for sturcture like above and
use it with xsdcxx?  If so, what am I missing?

I hope this kind of works and I just miss something.  I at least think
that this problem would be pretty common (think XHTML), but I failed
to dig to the bottom of it...

[1] http://www.musicxml.org/dtds/partwise.dtd
-- 
Thanks,
  ⡍⠁⠗⠊⠕ | Debian Developer <URL:http://debian.org/>
  .''`. | Get my public key via finger mlang/key at db.debian.org
 : :' : | 1024D/7FC1A0854909BCCDBE6C102DDFFC022A6B113E44
 `. `'
   `-      <URL:http://delysid.org/>  <URL:http://www.staff.tugraz.at/mlang/>




More information about the xsd-users mailing list