Hi Khaled, Thanks for your mail. Your explanation below is quite helpful to understand, xs:override semantics. I was reading the xs:override spec over the last few days, and got pretty involved in the details.
I am going to spend some time over the next few days, to understand xs:override in more detail, also taking help from the example you have given below. I am trying to write something for xs:override implementation, and would try to submit a patch for review with the list members, as soon as possible. PS: I am also changing my email address, for this list to the Apache address. On Thu, Oct 15, 2009 at 12:12 AM, Khaled Noaman <[email protected]> wrote: > > Hi Mukul and Hiranya, > > Let me chime in (I meant to reply earlier but got sidetracked by some other > work). > > Looking at the latest XML Schema 1.1 specification, I can see that the scope > of xs:override has changed quite a bit. I believe that we should start with a > fresh implementation (and not mimic the implementation of <xs:redefine> in > Xerces-J as is the case). > > The xs:override feature is much more complicated than it looks. I will try to > give a quick overview of how xs:override is meant to work as well as some of > its finer details. > > 1. xs:override only applies if the component to be overridden exists in the > overridden schema, e.g. > > Schema A > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:override schemaLocation="schemaB.xsd"> > <xs:complexType name="personName"> > <xs:sequence> > <xs:element name="givenName"/> > <xs:element name="surname"/> > </xs:sequence> > </xs:complexType> > </xs:override> > > ... > </xs:schema> > > Schema B > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:element name="phone" type="xs:string"/> > </xs:schema> > > In the above example, xs:override has no effect what so ever (i.e. the type > "personName" won't exist in the grammar and if you try to refer to it, you > will get an error message about trying to refer to an unknown type) > > 2. When overriding component(s) of another schema, the end result is that > <override> will be converted to <include>, e.g. > > Schema A > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:override schemaLocation="schemaB.xsd"> > <xs:complexType name="personName"> > <xs:sequence> > <xs:element name="givenName"/> > <xs:element name="surname"/> > </xs:sequence> > </xs:complexType> > </xs:override> > > ... > </xs:schema> > > Schema B > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:complexType name="personName"> > <xs:sequence> > <xs:element name="firstName"/> > <xs:element name="lastName"/> > </xs:sequence> > </xs:complexType> > <xs:element name="phone" type="xs:string"/> > </xs:schema> > > Once you apply the xs:override rules, you will end up with Schema A including > Schema B', with Schema B' containing the override components, e.g. > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:include schemaLocation="schemaB.xsd"/> > > ... > </xs:schema> > > Schema B' > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:complexType name="personName"> > <xs:sequence> > <xs:element name="givenName"/> > <xs:element name="surname"/> > </xs:sequence> > </xs:complexType> > > <xs:element name="phone" type="xs:string"/> > </xs:schema> > > > 3. xs:override is pervasive. If schema A override schema B and schema B > includes schema C, schema A will also overrides components in schema C, e.g. > > Schema A > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:override schemaLocation="schemaB.xsd"> > <xs:element name="e1" type="xs:int"/> > <xs:element name="e2" type="xs:date"/> > <xs:override> > > ... > </xs:schema> > > Schema B > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:include schemaLocation="schemaC.xsd"/> > > <xs:element name="e2" type="xs:string"/> > </xs:schema> > > Schema C > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:element name="e1" type="xs:float"/> > </xs:schema> > > We will need to override components in schema B as well as override schema C. > So, the first step would be to have schema A include schema B' and convert > the include of schema C to an override, e.g. > > Schema A > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:include schemaLocation="schemaB.xsd"/> > > ... > </xs:schema> > > Schema B' > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:override schemaLocation="schemaC.xsd"> > <element name="e1" type="xs:int"/> > <element name="e2" type="xs:date"/> > </xs:override> > > <xs:element name="e2" type="xs:date"/> > </xs:schema> > > Schema C > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:element name="e1" type="xs:float"/> > </xs:schema> > > We then override schema C (i.e. B' will include C'), e.g. > > Schema A > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:include schemaLocation="schemaB.xsd"/> > > ... > </xs:schema> > > Schema B' > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:include schemaLocation="schemaC.xsd"/> > > <xs:element name="e2" type="xs:date"/> > </xs:schema> > > Schema C' > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:element name="e1" type="xs:int"/> > </xs:schema> > > 4. You can have multiple override, e.g. schema A overrides schema B and > schema B overrides schema C. In this case, some components will be replaced > while others will be merged, e.g. > > Schema A > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:override schemaLocation="schemaB.xsd"> > <xs:element name="e1" type="xs:int"/> > <xs:element name="e2" type="xs:date"/> > <xs:override> > > ... > </xs:schema> > > Schema B > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:override schemaLocation="schemaC.xsd"> > <xs:element name="e2" type="xs:string"/> > <xs:simpleType name="s1"> > <xs:restriction base="xs:short"> > <xs:minInclusive value="1"/> > <xs:maxExclusive value="100"/> > </xs:restriction> > </xs:simpleType> > <xs:override> > > <xs:element name="e1" type="xs:time"/> > </xs:schema> > > Schema C > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:element name="e2" type="s1"/> > > <xs:simpleType name="s1"> > <xs:restriction base="xs:string"> > <xs:minLength value="5"/> > </xs:restriction> > </xs:simpleType> > </xs:schema> > > So, we apply override rules on B (replace matching components and merge extra > components to override, then include the new schema by A), e.g. > > Schema A > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:include schemaLocation="schemaB.xsd"/> > > ... > </xs:schema> > > Schema B' > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:override schemaLocation="schemaC.xsd"> > <xs:element name="e2" type="xs:date"/> > <xs:simpleType name="s1"> > <xs:restriction base="xs:short"> > <xs:minInclusive value="1"/> > <xs:maxExclusive value="100"/> > </xs:restriction> > </xs:simpleType> > <xs:element name="e1" type="xs:int"/> > <xs:override> > > <xs:element name="e1" type="xs:int"/> > </xs:schema> > > Schema C > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:element name="e2" type="s1"/> > > <xs:simpleType name="s1"> > <xs:restriction base="xs:string"> > <xs:minLength value="5"/> > </xs:restriction> > </xs:simpleType> > </xs:schema> > > The next step is to override schema C, e.g. > > Schema A > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:include schemaLocation="schemaB.xsd"/> > > ... > </xs:schema> > > Schema B' > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:include schemaLocation="schemaC.xsd"/> > > <xs:element name="e1" type="xs:int"/> > </xs:schema> > > Schema C' > > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > <xs:element name="e2" type="xs:date"/> > > <xs:simpleType name="s1"> > <xs:restriction base="xs:short"> > <xs:minInclusive value="1"/> > <xs:maxExclusive value="100"/> > </xs:restriction> > </xs:simpleType> > </xs:schema> > > > 5. Since xs:override applies to included schema(s) in the overriden schema, > you could end up with duplicate components (especially if you have a circular > case of include and override). Let's consider the following case: schema A > include schema B, schema B overrides schema C, and schema C include schema B. > In this case we will end up with two versions of schema B (the one included > by schema A, call it B, and the one overriden by C, call it B'). This means > that we will process duplicate components (common components in B and B' and > need to flag these as errors). > > 6. You have to also take into account circular overrides, e.g. schema A > overrides schema B which overrides schema A. > > Regards, > Khaled -- Regards, Mukul Gandhi --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
