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





Mukul Gandhi <[email protected]> 
09/26/2009 10:22 PM
Please respond to
[email protected]


To
[email protected]
cc

Subject
Re: XML Schema 1.1 xs:override implementation






Hi Hiranya,
  Thanks for your reply. Pls see some of my comments, below.

On Sat, Sep 26, 2009 at 11:33 AM, Hiranya Jayathilaka
<[email protected]> wrote:
> You are correct. I started revising my patch against the specs but never
> finished it due to a bunch of other commitments.

no problems! We all get busy some or the other time.

> However what I learnt
> during the little time I spent on this was that my patch to implement
> xs:override covers most (if not all) of the requirements stated in the
> specs.

That's great. When I looked at your patch some time ago, I felt it had
implemented a good framework for xs:override. Though, we need to check
the patch you submitted, for finer points as well. But it's a good
starting point, and we must start from there.

> That's great. However I would like if you can first take the patch I 
have
> submitted and start from where I've left instead of beginning from the
> scratch. It's a pretty simple code so I'm sure you can get hold of the 
logic
> implemented there easily.

Yes, definitely. I am going to start from your patch for this
implementation, and would discuss on the list, in case we face
implementation difficulty.

> Also now that the GSoC is over and some of the other Apache releases 
I've
> been working on in the past few weeks are coming to an end I'll have 
some
> time to actually devote to this in the weeks to come. So I can help you 
with
> revising the patches and refining the design/implementation.

That's great. I'll try to submit something about xs:override in coming
days (as discussed, with an extension from your patch), and then we
can progress from there.

> +1

Thanks!


-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to