tags:

views:

95

answers:

1

I am having trouble defining the content-type of an element ("phonenumber") whilst at the same time defining a property ("location") with enumeration restrictions.

Here's where I'm stuck:

<xs:element name="phonenumbers">
    <xs:complexType>
        <xs:sequence maxOccurs="unbounded">
            <xs:element name="phonenumber">
                <!--
                Try #1:
                Define the type of the attribute "location" and the
                content-type of the element "phonenumber". But without
                enumeration restrictions on "location".
                -->

                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:integer">
                            <xs:attribute name="location" type="xs:string"/>                                                        
                        </xs:extension>                                                    
                    </xs:simpleContent>
                </xs:complexType>

                <!--
                Try #2:
                Enumerables in attribute "location" with no content-type
                of the element "phonenumber", thus being unable to put
                anything in it.
                -->

                <xs:complexType>                                                
                    <xs:attribute name="location">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:enumeration value="Home"/>
                                <xs:enumeration value="Work"/>
                                <xs:enumeration value="Mobile"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:complexType>

            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
+1  A: 

What about

<xs:element name="phonenumbers">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="phonenumber" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:simpleContent>
            <xs:extension base="xs:integer">
              <xs:attribute name="location" use="required">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:enumeration value="Home"/>
                    <xs:enumeration value="Work"/>
                    <xs:enumeration value="Mobile"/>
                  </xs:restriction>
                </xs:simpleType>
              </xs:attribute>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
Stefan Gehrig