-----Original Message-----
From: Richard Heintze [mailto:[EMAIL PROTECTED]
Sent: Monday, September 23, 2002 2:12 PM
To: [EMAIL PROTECTED]
Subject: Schema Qs: Attributes and restrictions on xsd:patters(1) How can I check the syntax of an attribute? I want to say <call phone="303 444 2501"> check on bn book </call>. Can an attribute be a derived simple type? What is the syntax?
[Chudasama, Chetan]You can use simpleType's to derive attributes from. The XSD Specification is also clear on that. Thus you could define the call element as:<xs:element name="call"><xs:complexType><xs:attribute name="phone"><xs:simpleType><xs:restriction base="xs:string"><xs:pattern value="\p{Nd}{3} \p{Nd}{3} \p{Nd}{4}( x \p{Nd}+)?"/></xs:restriction></xs:simpleType></xs:attribute></xs:complexType></xs:element>(2) How do I create an element like this <phone loc="home">303 444 2501</phone>?
Here is my attempt:
Why doesn't the latest xerces-J let me put an attribute on a derivation simple type?
<xsd:simpleType name="phone_type">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\p{Nd}{3} \p{Nd}{3} \p{Nd}{4}( x \p{Nd}+)?"/>
</xsd:restriction>
<xsd:attribute name="loc" type="xsd:string" use="optional"/>
</xsd:simpleType>[Error] phonelog.xsd:37:65: s4s-elt-must-match: The content of 'simpleType' must match (annotation?, (restriction | list | union)).
[Chudasama, Chetan] The error in this case is because you cannot use the element 'attribute' while defining a simpleType. A simpleType can only contain the following as its children:0 or 1 annotation followed by exactly one of restriction, list or union as shown in the error.
I suggest you look at the W3C Schema part -0 which is a primer to get these basic concepts clear (http://www.w3.org/TR/xmlschema-0/). Also if you use some tools to create the Schema then you would be reducing such mistakes.
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
Richard,
See my
comments below. Hope it helps.
Cheers,
Chetan
- Schema Qs: Attributes and restrictions on xsd:patters Richard Heintze
- Chudasama, Chetan
