JAXB 1.0 と内部で記述された MusicXML 1.0 スキーマを使用する Java アプリケーションを更新して、JAXB 2.2 とベンダー提供の MusicXML 3.0 スキーマを使用します。JAXB 2.2 を使用して <part-list> の複数の <score-part> 子要素を持つファイルを非整列化すると、1 つの <score-part> 要素のみが返されます。現在、追加の <score-parts> を取得するために DOM で回避策を使用していますが、データを取得するためにファイルを 2 回解析しているため、これはあまり望ましくありません。<part-list> 内のすべての <score-parts> を JAXB に返させるにはどうすればよいですか?
<part-list> の MusicXML 1.0 スキーマ スニペット
<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>
<part-list> の MusicXML 3.0 スキーマ スニペット
<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 スニペット
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
}
}
テスト データには、 The Unofficial MusicXML Test Suite のファイル 41a-MultiParts-Partorder.xml および 41b-MultiParts-MoreThan10.xml を使用しています。
MusicXML 3.0 の JAXB バインディングを構築する場合、JAXB から次の (または同様の) エラーが発生する可能性があります。
[ERROR] Property "Segno" is already defined. Use <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 <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
その場合は、ここで概説されている手順に従ってください