0

So i have an element phone

 <phone carrier="A">9991234567</phone>

with a carrier attribute with defined values. I've defined it using complexType. Now, the content of the phones also needs to have a restriction (Regex).

<xs:element name="phone" type="phoneType" />

<xs:complexType name="phoneType">
    <xs:attribute name="carrier" type="carrierType" />
</xs:complexType>

<xs:simpleType name="carrierType">
    <xs:restriction base="xs:string" >
        <xs:enumeration value="A" />
        <xs:enumeration value="B" />
    </xs:restriction>
</xs:simpleType>

1 Answers1

0

You want a "complex type with simple content". For an example see

XSD : How to use both value and attribute

But in your case the base type is not xs:string, rather some restriction from string. So define your restricted type, for example

<xs:simpleType name="phoneNr">
  <xs:restriction base="xs:string">
   <xs:pattern value="[0-9]+"/>
  </xs:restriction>
</xs:simpleType>

and then define carrierType as an extension of phoneNr (the extension being the attribute).

Community
  • 1
  • 1
Michael Kay
  • 156,231
  • 11
  • 92
  • 164