Reputation: 177
I am trying to write a schema file to validate xml. I am using Xerces to do the validation. I get this message :
Line: 10 Column: 15 Message: element 'chord' is not allowed for content model '(chord)'
But I don't understand what it trying to tell me. Here is my XML and my XSD
Many thanks in advance.
Here is my XML
<song>
<section tempo='120' producer='Vanilla'>
<harmony key='Eb'>
<chord duration='4' chord='Cm'/>
<chord duration='4' chord='Fm'/>
<chord duration='4' chord='Ab'/>
<chord duration='4' chord='Bb'/>
</harmony>
<orchestration>
<track type='Agent' instrumentID='HarderTo_Drums' pattern='HarderTo/HarderTo_Drums_Verse' micID='' gain='0.1'/>
</orchestration>
</section>
</song>
Here is my XSD :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of attributes -->
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="agentID" type="xs:string"/>
<xs:attribute name="insrumentID" type="xs:string"/>
<xs:attribute name="pattern" type="xs:string"/>
<xs:attribute name="role" type="xs:string"/>
<xs:attribute name="gain" type="xs:float"/> <!-- This should be a positive float value. Should have min and max values -->
<xs:attribute name="id" type="xs:string"/> <!-- This should be a GUID -->
<xs:attribute name="autotuneID" type="xs:nonNegativeInteger"/>
<xs:attribute name="key" type="xs:string"/>
<xs:attribute name="duration" type="xs:float"/>
<xs:attribute name="chord" type="xs:string"/>
<xs:attribute name="tempo" type="xs:positiveInteger"/>
<xs:attribute name="producer" type="xs:string"/>
<!-- definition of a agent track -->
<xs:complexType name="agentTrack">
<xs:attribute ref="type" use="required"/>
<xs:attribute ref="insrumentID" use="required"/>
<xs:attribute ref="pattern" use="required"/>
<xs:attribute ref="role"/>
<xs:attribute ref="gain"/>
</xs:complexType>
<!-- definition of a agent track -->
<xs:complexType name="drumTrack">
<xs:attribute ref="type" use="required"/>
<xs:attribute ref="insrumentID" use="required"/>
<xs:attribute ref="pattern" use="required"/>
<xs:attribute ref="gain"/>
</xs:complexType>
<!-- definition of a lick track -->
<xs:complexType name="lickTrack">
<xs:attribute ref="type" use="required"/>
<xs:attribute ref="agentID" use="required"/>
<xs:attribute ref="pattern" use="required"/>
<xs:attribute ref="role"/>
<xs:attribute ref="gain"/>
</xs:complexType>
<!-- definition of a vocal track -->
<xs:complexType name="vocalTrack">
<xs:attribute ref="type" use="required"/>
<xs:attribute ref="id" use="required"/>
<xs:attribute ref="agentID" use="required"/>
<xs:attribute ref="insrumentID" use="required"/>
<xs:attribute ref="gain"/>
</xs:complexType>
<!-- defination of a chord -->
<xs:complexType name="chordType">
<xs:attribute ref="duration" use="required"/>
<xs:attribute ref="chord" use="required"/>
</xs:complexType>
<!-- definition of a harmony -->
<xs:complexType name="harmony">
<xs:sequence>
<xs:element name="chord" type="chordType" minOccurs="1"/>
</xs:sequence>
<xs:attribute ref="key" use="required"/>
</xs:complexType>
<!-- definition of an orchestration -->
<xs:complexType name="orchestration">
<xs:all>
<xs:element name="agentTrack" type="agentTrack" minOccurs="0"/>
<xs:element name="drumTrack" type="drumTrack" minOccurs="0"/>
<xs:element name="lickTrack" type="lickTrack" minOccurs="0"/>
<xs:element name="vocalTrack" type="vocalTrack" minOccurs="0"/>
</xs:all>
</xs:complexType>
<!-- definition of a section -->
<xs:complexType name="section">
<xs:all>
<xs:element name="harmony" type="harmony" minOccurs="1" maxOccurs="1"/>
<xs:element name="orchestration" type="orchestration" minOccurs="1" maxOccurs="1"/>
</xs:all>
<xs:attribute ref="tempo" use="required"/>
<xs:attribute ref="producer" use="required"/>
</xs:complexType>
<!-- definition of a song -->
<xs:element name="song">
<xs:complexType>
<xs:all>
<xs:element name="section" type="section" minOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
Upvotes: 0
Views: 101
Reputation: 122364
<xs:element name="chord" type="chordType" minOccurs="1"/>
You haven't specified maxOccurs
and the default for that is 1, so the schema requires exactly 1 chord
element here and it will complain when it sees the second one. Add maxOccurs="unbounded"
if you want to allow more than one chord per harmony.
Upvotes: 2