0

This seems fairly simple but I haven't found an answer yet. I have xml using an attribute and value together:

<BusinessIdentifier businessIdentifierType="Customer Number">D123456788</BusinessIdentifier>

Which should validate against the schema:

<xs:simpleType name="BusinessIdentifierTypes">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Plan Number"/>
        <xs:enumeration value="Customer Number"/>
        <xs:enumeration value="Scheme Number"/>
        <xs:enumeration value="Agency Code"/>
    </xs:restriction>
</xs:simpleType>

<xs:element name="BusinessIdentifier">
<xs:complexType>
<xs:attribute name="businessIdentifierType" type="BusinessIdentifierTypes" use="required"/>                                             
</xs:complexType>
</xs:element>

I can see that I'm missing somewhere for the value D123456789 but I'm not sure how to put that in the same element as well as the attribute. This looked similar to what I was trying to achieve XML Schema How to Restrict Attribute by Enumeration but I got an error when trying to use the xs:extension tag

Community
  • 1
  • 1

2 Answers2

0

You need to define the type as a "complex type with simple content". Hopefully that will help you look it up in your favourite XML Schema reference book.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

Yes, thanks, I fixed this by using the following in the schema:

<xs:element name="BusinessIdentifier">
                                        <xs:complexType>
                                            <xs:simpleContent>                                                  <xs:extension base="xs:string">                                                     <xs:attribute name="businessIdentifierType" type="BusinessIdentifierTypes" use="required"/>
                                                </xs:extension>
                                            </xs:simpleContent>
                                        </xs:complexType>
                                    </xs:element>