Goals:
Create an XSD where the "type" attribute is required for every xs:element defined in the schema
Be able to re-use the redefined
http://www.w3.org/2001/XMLSchema
in other schemas to force all defined xs:element(s) to require the "type" attribute
For example, I would like the following to be "not valid" in our XSD (e.g. in XMLSpy)
<xs:element name="SomeElement"/>
whereas the following would be valid
<xs:element name="SomeElement" type="abc:SomeType"/>
Here is an example of a schema where I have attempted to redefine the <xs:complexType name="element">
to require the "type" attribute.
<?xml version="1.0"?>
<!-- edited with XMLSpy v2013 (http://www.altova.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:redefine schemaLocation="http://www.w3.org/2001/XMLSchema.xsd">
<xs:complexType name="element" abstract="true">
<xs:complexContent>
<xs:restriction base="xs:element">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:QName"/>
</xs:simpleType>
</xs:attribute>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="topLevelElement">
<xs:complexContent>
<xs:restriction base="xs:topLevelElement"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="localElement">
<xs:complexContent>
<xs:restriction base="xs:localElement"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="narrowMaxMin">
<xs:complexContent>
<xs:restriction base="xs:narrowMaxMin"/>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
<xs:element name="SomeElement"/>
</xs:schema>
Now, there are some interesting aspects of this schema, and some odd behavior in XMLSpy 2013 (no service pack):
In "Text" view, and attempting to save, XMLSpy indicates the schema is "not valid"
In "Schema" view, and attempting to save, XMLSpy indicates the schema is valid
An attempt to create a sample XML file in XMLSpy will result in an error indicating the schema is not valid
The only part of the schema that should not be valid is the
<xs:element name="SomeElement">
because it has not been defined with a "type" attribute.The errors that occur are related to duplicate declarations; but what is being attempted is a redefinition rather than another declaration.
Questions:
- Is it possible to redefine
<xs:complexType name="element">
to require the "type" attribute? - Is it possible to use this redefined type in other XSD(s) with a different "targetNamespace"?