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>
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.