This page contains examples of various XML Schema fragments that you might find
useful.
For discussion of JMRI's use of XML Schema, including info on preferred patterns and
organization, see another page.
<xs:element name="someData" minOccurs="0" maxOccurs="1">
That doesn't specify any typing. If you want e.g. to enforce integer:
<xs:element name="someIntThing" >
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:int" />
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="sample" type="SampleType"
minOccurs="0" maxOccurs="unbounded" />
<xs:complexType name="SampleType">
<xs:attribute name="foo" />
<xs:attribute name="bar" />
</xs:complexType>
Can also be combined if you think it's unlikely to be used elsewhere:
<xs:element name="sample"
minOccurs="0" maxOccurs="unbounded" />
<xs:complexType>
<xs:attribute name="foo" />
<xs:attribute name="bar" />
</xs:complexType>
</xs:element>
<xs:element name="someIntThing" >
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:int">
<xs:attribute name="someInt" type="xs:int"/>
<xs:attribute name="someText" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:simpleType name="yesNoType">
<xs:annotation>
<xs:documentation>
General definition of string that's either "yes" or "no".
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:token">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
Then putting it on an attribute is simple:
<xs:attribute name="opsOnly" type="yesNoType"/>
<xs:element name="relation">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="ge"/>
<xs:enumeration value="lt"/>
<xs:enumeration value="eq"/>
<xs:enumeration value="ne"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:attributeGroup name="EditorCommonAttributesGroup">
<xs:annotation>
<xs:documentation>
Define the XML stucture for storing common PositionableLabel child attributes
</xs:documentation>
<xs:appinfo>
jmri.jmrit.display.configurexml.PositionableLabelXml#storeCommonAttributes
</xs:appinfo>
</xs:annotation>
<xs:attribute name="x" type="xs:int" use="required" />
<xs:attribute name="y" type="xs:int" use="required" />
<xs:attribute name="level" type="xs:int" />
<xs:attribute name="forcecontroloff" type="trueFalseType" default="false" />
</xs:attributeGroup>
and example use in some later type:
<xs:attributeGroup ref="EditorCommonAttributesGroup" />