- From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
- Date: 20 Mar 2001 09:23:41 +0000
- To: "Slein, Judith A" <JSlein@crt.xerox.com>
- Cc: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>, "Corda, Ugo" <Ugo.Corda@usa.xerox.com>, "Sembower, Neil R" <NSembower@crt.xerox.com>, "Stumbo, William K" <WStumbo@crt.xerox.com>
"Slein, Judith A" <JSlein@crt.xerox.com> writes:
> We've been struggling to understand the XML syntax of restricted types, and
> in particular what the effect should be of not listing an element or
> attribute from the base type. As I read the new revision of XML Structures,
> it looks like
>
> Any attribute declared in the base type can be used in instances of the
> restricted type unless you explicitly say use="prohibited" in the restricted
> type. (You do not have to repeat attributes from the base type in order for
> them to be used in instances of the restricted type.)
Yes.
> Elements declared in the base type cannot be used in instances of the
> restricted type unless you also list them in the definition of the
> restricted type. So not mentioning an element from the base type is
> equivalent to listing it with maxOccurs="0" in the restricted type.
Yes.
> However, I tried the following experiments with 3 different validating
> parsers and got mixed results:
>
> Base type for all tests is:
>
> <complexType name="Basic">
> <sequence>
> <element ref="myns:Recipient"/>
> <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
> <element ref="myns:City"/>
> <element ref="myns:State"/>
> <element ref="myns:Zip" minOccurs="0"/>
> </sequence>
> <attribute name="ID" type="ID" use="required"/>
> <attribute name="Description" type="string"/>
> </complexType>
>
> <element name="Recipient" type="string"/>
> <element name="Street" type="string"/>
> <element name="City" type="string"/>
> <element name="State" type="string"/>
> <element name="Zip" type="integer"/>
>
> Test 1: Attribute Description is not listed in the restricted type
>
> <element name="El1" type="myns:RestrictedAttrsOmit"/>
> <complexType name="RestrictedAttrsOmit">
> <complexContent>
> <restriction base="myns:Basic">
> <sequence>
> <element ref="myns:Recipient"/>
> <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
> <element ref="myns:City"/>
> <element ref="myns:State"/>
> <element ref="myns:Zip"/>
> </sequence>
> <attribute name="ID" type="ID" use="required"/>
> </restriction>
> </complexContent>
> </complexType>
>
> <El1 ID="myID" Description="some text"
> xmlns="http://www.xerox.com/xmlschemas/MyNamespace"
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:schemaLocation="http://www.xerox.com/xmlschemas/MyNamespace
> Restriction.xsd">
> <Recipient>J. Slein</Recipient>
> <Street>309 West Ave.</Street>
> <City>Wilderness</City>
> <State>ME</State>
> <Zip>00001</Zip>
> </El1>
>
> Results:
> XSV -- valid
> XML Spy -- valid
Well, I think it's valid.
> XML Instance -- invalid
>
> Test 2: Restricted type has Description with use="prohibited"
>
> <element name="El2" type="myns:RestrictedAttrsProhibit"/>
> <complexType name="RestrictedAttrsProhibit">
> <complexContent>
> <restriction base="myns:Basic">
> <sequence>
> <element ref="myns:Recipient"/>
> <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
> <element ref="myns:City"/>
> <element ref="myns:State"/>
> <element ref="myns:Zip"/>
> </sequence>
> <attribute name="ID" type="ID" use="required"/>
> <attribute name="Description" type="string" use="prohibited"/>
> </restriction>
> </complexContent>
> </complexType>
>
> <El2 ID="myID" Description="some text"
> xmlns="http://www.xerox.com/xmlschemas/MyNamespace"
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:schemaLocation="http://www.xerox.com/xmlschemas/MyNamespace
> Restriction.xsd">
> <Recipient>J. Slein</Recipient>
> <Street>309 West Ave.</Street>
> <City>Wilderness</City>
> <State>ME</State>
> <Zip>00001</Zip>
> </El2>
>
> Results:
> XSV -- invalid
> XML Spy -- invalid
Well, I think it's invalid.
> XML Instance -- valid
>
> Test 3: Element Zip is not listed in the restricted type
>
> <element name="El3" type="myns:RestrictedElsOmit"/>
> <complexType name="RestrictedElsOmit">
> <complexContent>
> <restriction base="myns:Basic">
> <sequence>
> <element ref="myns:Recipient"/>
> <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
> <element ref="myns:City"/>
> <element ref="myns:State"/>
> </sequence>
> <attribute name="ID" type="ID" use="required"/>
> <attribute name="Description" type="string"/>
> </restriction>
> </complexContent>
> </complexType>
>
> <El3 ID="myID" Description="some text"
> xmlns="http://www.xerox.com/xmlschemas/MyNamespace"
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:schemaLocation="http://www.xerox.com/xmlschemas/MyNamespace
> Restriction.xsd">
> <Recipient>J. Slein</Recipient>
> <Street>309 West Ave.</Street>
> <City>Wilderness</City>
> <State>ME</State>
> <Zip>00001</Zip>
> </El3>
>
> Results:
> XSV -- invalid
> XML Spy -- invalid
> XML Instance -- invalid
Not valid, because Zip wasn't optional in base type.
> Test 4: Element Zip has maxOccurs="0" in restricted type
>
> <element name="El4" type="myns:RestrictedElsMaxOccurs"/>
> <complexType name="RestrictedElsMaxOccurs">
> <complexContent>
> <restriction base="myns:Basic">
> <sequence>
> <element ref="myns:Recipient"/>
> <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
> <element ref="myns:City"/>
> <element ref="myns:State"/>
> <element ref="myns:Zip" minOccurs="0" maxOccurs="0"/>
> </sequence>
> <attribute name="ID" type="ID" use="required"/>
> <attribute name="Description" type="string"/>
> </restriction>
> </complexContent>
> </complexType>
>
> <El4 ID="myID" Description="some text"
> xmlns="http://www.xerox.com/xmlschemas/MyNamespace"
> xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> xsi:schemaLocation="http://www.xerox.com/xmlschemas/MyNamespace
> Restriction.xsd">
> <Recipient>J. Slein</Recipient>
> <Street>309 West Ave.</Street>
> <City>Wilderness</City>
> <State>ME</State>
> <Zip>00001</Zip>
> </El4>
>
> Results:
> XSV -- valid
> XML Spy -- valid
Not valid, because Zip wasn't optional in base type. I've fixed the
bug in XSV that lets this through.
> XML Instance -- invalid
>
> Can someone explain what the results of these tests really should be and
> why? Thanks.
I can't comment on the others, I've explained why I think XSV is right
in three out of four cases, and fixed the fourth :-)
ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
W3C Fellow 1999--2001, part-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
Received on Tuesday, 20 March 2001 04:23:54 UTC