Don Adams wrote:
I would like to have the following XML:
<phone type="work">555-123-1234</phone>
<phone type="home">555-123-4321</phone>
Is it possible to write a schema to restrict the contents of
the type attribute to be enumerated ("work" or "home") AND restrict the
contents of the <phone> element to match the pattern \d\d\d-\d\d\d-\d\d\d\d
?
I know how to do one or the other, but I haven't figured out a way
to do both. It seems that the pattern restriction can only be
applied to a simple type, but a simple type cannot have attributes. So
what I want to do may not be possible. Is this correct?
Here is a schema that defines your element phone and an element root to
contain a sequence of phone elements
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="phone" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="phone">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="phoneNo">
<xs:attribute name="type" type="homeWork" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:simpleType name="phoneNo">
<xs:restriction base="xs:string">
<xs:pattern value="\d{3}-\d{3}-\d{4}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="homeWork">
<xs:restriction base="xs:string">
<xs:enumeration value="home" />
<xs:enumeration value="work" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
--
Martin Honnen
http://JavaScript.FAQTs.com/