I have an XML schema that includes multiple addresses:
<xs:element name='personal_address' maxOccurs='1'> <!-- address fields go here --> </xs:element> <xs:element name='business_address' maxOccurs='1'> <!-- address fields go here --> </xs:element>
Within each address element, I include a ‘US State’ enumeration:
<xs:simpleType name='state'> <xs:restriction base='xs:string'> <xs:enumeration value='AL' /> <xs:enumeration value='AK' /> <xs:enumeration value='AS' /> .... <xs:enumeration value='WY' /> </xs:restriction> </xs:simpleType>
How do I go about writing the ‘US State’ enumeration once and re-using it in each of my address elements? I apologize in advance if this is a n00b question — I’ve never written an XSD before.
My initial stab at it is the following:
<xs:element name='business_address' maxOccurs='1'> <!-- address fields go here --> <xs:element name='business_address_state' type='state' maxOccurs='1'></xs:element> </xs:element>
I think you are on the right tracks. I think its more to do with XML namespaces. Try the following:
Note that the type is tns:state not just state
And then this is how you would use it:
Notice that this XML uses a default namespace the same as the targetNamespace of the XSD