Hi Pete,
Oh yes, sure - I didn't think of that case. If you are "ref"-ing the
element declarations that are in the original namespace, it's OK (they
can be the same child elements or a restricted set of those child
elements).
Its just if you were "ref"-ing element in the new namespace that would
cause a problem.
And yes, it works in a parallel way for attributes. If you use
attributeFormDefault="unqualified" (the default behavior), you're fine.
If you're using attributes in namespaces, the attributes have to be in
the same namespace in the restricted type.
Thanks,
Priscilla
Thanks for the discussion on this.
I've experimented / digested a bit and have the following observations
(with example code for each):
Background is I have a large XSD that I want to subset via complex
type restriction, with the restricted types defined in a namespace
different than the namespace of the XSD I am subsetting. For
discussion, lets say there is a "base" namespace and a "restricted"
namespace. The restricted types will be defined in the "restricted"
namespace.
I (at present) see 2 approaches:
1) The base namespace has global element and complex type definitions,
however the global complex types have some local element definitions.
For the types in the restricted namespace, I need to repeat the
mandatory content of the types in the base namespace that I am
restricting. However, I can't really "refer" to the mandatory content
of the base types since some of that content is local in the base
namespace.
So... I can say elementFormDefault="unqualified" in both the base XSD
and restricted XSD, and can then create an instance document
containing the restricted type, whose content is the mandatory content
of the base namespace, and the element names are unqualified.
<?xml version="1.0" encoding="UTF-8"?>
<res:ARestricted xmlns:res="
http://www.example.org/Restriction"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.example.org/NewXMLSchemaExtension
RestrictionWithLocalElementDefs.xsd ">
<E1>E1</E1>
</res:ARestricted>
2) The base namespace has ALL global element and complex type
definitions; there are no local element definitions or anonymous
complex types. I believe this is the "salami slice" design pattern.
For the types in the restricted namespace, I need to repeat the
mandatory content of the types in the base namespace that I am
restricting. Since all elements have global definitions, I can
"refer" to them via a ref.
So... I can say elementFormDefault="qualified" in both the base XSD
and restricted XSD, and can then create an instance document
containing the restricted type, whose content is the mandatory content
of the base namespace, and the element names are qualified.
<?xml version="1.0" encoding="UTF-8"?>
<res:ARestricted xmlns:res="
http://www.example.org/Restriction"
xmlns:base="
http://www.example.org/Base"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.example.org/NewXMLSchemaExtension
NewXMLSchemaRestriction.xsd ">
<base:E1>E1</base:E1>
</res:ARestricted>
I much perfer option 2 since all elements are prefixed with
appropriate namespace. This gets to the rationale of many of the
Naming and Design Rules I think. I'm not an expert on NDRs, however,
defining all elements and types globally means (among other things)
that I can subset/restrict to a different namespace and have all
resulting elements prefixed with appropriate namespace.
----------------------------------------------
XDSs for option 1
----------------------------------------------
-- Base XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns="
http://www.example.org/Base"
targetNamespace="
http://www.example.org/Base"
elementFormDefault="unqualified">
<xs:element name="A" type="AType" />
<xs:complexType name="AType">
<xs:sequence>
<xs:element name="E1" type="xs:string" />
<xs:element name="E2" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>
-- Restricting XSD, with restricted types in different namespace
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns="
http://www.example.org/Restriction"
targetNamespace="
http://www.example.org/Restriction"
xmlns:base="
http://www.example.org/Base"
elementFormDefault="unqualified">
<xs:import namespace="
http://www.example.org/Base"
schemaLocation="BaseWithLocalElementDefs.xsd" />
<xs:element name="ARestricted" type="ARestrictedType" />
<xs:complexType name="ARestrictedType">
<xs:complexContent>
<xs:restriction base="base:AType">
<xs:sequence>
<xs:element name="E1" type="xs:string" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
-- Instance
<?xml version="1.0" encoding="UTF-8"?>
<res:ARestricted xmlns:res="
http://www.example.org/Restriction"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.example.org/NewXMLSchemaExtension
RestrictionWithLocalElementDefs.xsd ">
<E1>E1</E1>
</res:ARestricted>
----------------------------------------------
XDSs for option 2
----------------------------------------------
-- Base XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns="
http://www.example.org/Base"
targetNamespace="
http://www.example.org/Base"
xmlns:tns="
http://www.example.org/NewXMLSchema"
elementFormDefault="qualified">
<xs:element name="E1" type="E1Type" />
<xs:simpleType name="E1Type">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:element name="E2" type="E2Type" />
<xs:simpleType name="E2Type">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:element name="A" type="AType" />
<xs:complexType name="AType">
<xs:sequence>
<xs:element ref="E1" />
<xs:element ref="E2" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>
-- Restricting XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns="
http://www.example.org/Restriction"
targetNamespace="
http://www.example.org/Restriction"
xmlns:base="
http://www.example.org/Base"
elementFormDefault="qualified">
<xs:import namespace="
http://www.example.org/Base"
schemaLocation="BaseWithGlobalElementDefs.xsd" />
<xs:element name="ARestricted" type="ARestrictedType" />
<xs:complexType name="ARestrictedType">
<xs:complexContent>
<xs:restriction base="base:AType">
<xs:sequence>
<xs:element ref="base:E1" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
-- Instance
<?xml version="1.0" encoding="UTF-8"?>
<res:ARestricted xmlns:res="
http://www.example.org/Restriction"
xmlns:base="
http://www.example.org/Base"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.example.org/NewXMLSchemaExtension
NewXMLSchemaRestriction.xsd ">
<base:E1>E1</base:E1>
</res:ARestricted>