I think I need to do this with XSD 1.0, but anyway I will ask ... I have complexType in the file, say a.xsd . Basically, I can not touch this file. In particular, I cannot change its targetNamespace . An example is:
<xs:schema targetNamespace="http://myns.original" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:orig="http://myns.original"> <xs:element name="config" type="orig:ConfigType"/> <xs:complexType name="ConfigType"> <xs:sequence> <xs:element name="fieldA" type="xs:integer" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:schema>
I have a second b.xsd file where I extend the type defined in a.xsd and redefine the element previously defined in a.xsd using substitutionGroup . For now, everything is fine, and the following example looks fine:
<xs:schema targetNamespace="http://myns.myns" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:myns="http://myns.myns" xmlns:orig="http://myns.original"> <xs:import namespace="http://myns.original" schemaLocation="a.xsd"/> <xs:complexType name="ConfigType"> <xs:complexContent> <xs:extension base="orig:ConfigType"> <xs:sequence> <xs:element name="fieldB" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="config" type="myns:ConfigType" substitutionGroup="orig:config"/> </xs:schema>
Problems: One field in the original complexType is optional ( minOccurs=0 ). Now I need to override this type so that this field is required ( minOccurs=1 ). I suggested that this could be achieved with xsd:redefine , so I tried the following:
<xs:schema targetNamespace="http://myns.myns" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:myns="http://myns.myns"> <xs:redefine schemaLocation="b.xsd"> <xs:complexType name="ConfigType"> <xs:complexContent> <xs:restriction base="myns:ConfigType"> <xs:sequence> <xs:element name="fieldA" minOccurs="1"/> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> </xs:redefine> </xs:schema>
But I get the following messages:
There is not a complete functional mapping between the particles. Error for type 'ConfigType'. The particle of the type is not a valid restriction of the particle of the base.
Honestly, I do not quite understand these messages, but after some investigation it seems that the actual problem is that the redefined fields should belong to the same namespace as the redefinition. In my case, I am trying to limit the orig:fieldA in the http://myns.original in a file with targetNamespace = "http: //myns.myns". Of course, if the extension continued the type in c.xsd , as I did in b.xsd , there is no problem since I am not trying to change anything from another namespace.
Does anyone know if this can be achieved? One solution is to replicate the definitions, which will be changed in another a_2.xsd file, with the right targetNamespace . But this is a very undesirable and unattainable solution for a complex system.