2

I am updating a java application that uses JAXB 1.0 and internally written MusicXML 1.0 schemas, to use JAXB 2.2 and the vendor provided MusicXML 3.0 schemas. When I unmarshall a file with multiple <score-part> child elements for <part-list> using JAXB 2.2 only 1 <score-part> element is returned. I am currently using a workaround with DOM to get the addidiontal <score-parts> but this is not very desireable since I'm parsing the file twice to get the data. How can I get JAXB to return all <score-parts> in a <part-list>?

MusicXML 1.0 schema snippet for <part-list>

<xs:element name="part-list">
<xs:complexType>
  <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="unbounded" ref="part-group"/>
    <xs:element ref="score-part"/>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="part-group"/>
      <xs:element ref="score-part"/>
    </xs:choice>
  </xs:sequence>
</xs:complexType>
</xs:element>

MusicXML 3.0 schema snippet for <part-list>

<xs:complexType name="part-list">       
<xs:sequence>
    <xs:group ref="part-group" minOccurs="0" maxOccurs="unbounded"/>
    <xs:group ref="score-part"/>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:group ref="part-group"/>
        <xs:group ref="score-part"/>
    </xs:choice>
</xs:sequence>
</xs:complexType>

Java snippet for unmarshalling

package test;
import java.io.FileInputStream;
import java.util.*;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import recodare.MusicXML.*;
import javax.xml.bind.JAXBElement;


public class MusicXMLReader{

    private java.lang.String m_sXMLFielPath = "";
    private ScorePartwise m_spScorePartwise = null;
    public MusicXMLReader(java.lang.String filePath){
        m_sXMLFilePath = filePath;
    }
    public void processXML() throws Exception{

        JAXBContext jc = JAXBContext.newInstance("recodare.MusicXML");
        Unmarshaller u = jc.createUnmarshaller();
        m_spScorePartwise = (ScorePartwise)u.unmarshal(new FileInputStream(m_sXMLFilePath));

        PartList pl = m_spScorePartwise.getPartList();
        ScorePart scorePart = pl.getScorePart(); // 1st score-part
        // for remaining score-part or part-group this list is null even when part-list  
        // has multiple score-part elements
        List<Object> listPartGroupOrScorePart = pl.getPartGroupOrScorePart(); 
        //continue processing file

    }
}

For test data i am using files 41a-MultiParts-Partorder.xml and 41b-MultiParts-MoreThan10.xml from The Unofficial MusicXML Test Suite

If you wish to build the JAXB bindings for MusicXML 3.0 you may get the following(or similar) errors from JAXB

[ERROR] Property "Segno" is already defined. Use &lt;jaxb:property> to resolve this conflict.
line 2793 of file: musicxml.xsd

[ERROR] The following location is relevant to the above error
line 2800 file: musicXML.xsd
[ERROR] Property "Coda" is already defined. Use &lt;jaxb:property> to resolve this conflict.
line 2794 of musicXML.xsd

[ERROR] The following location is relevant to the above error
line 2801 of file: musicXML.xsd
[ERROR] Element "link" shows up in more than one properties.
line 4765 of file: musicXML.xsd
[ERROR] Element "bookmark" shows up in more than one properties.
line 4766 of file: musicXML.xsd

in which case follow the steps outlined here

elliot-j
  • 10,709
  • 3
  • 19
  • 18

0 Answers0