RE: Both extending and restricting with <redefine>

> Intuitively, it would be safer to go through two levels of xs:redefine. 

I'm assuming that by "two levels" you mean two separate schemas, so I
made another little test case (again at http://www.ruleml.org/0.89/xsd):

m.xsd is the same as the previous a.xsd

n.xsd redefines m.xsd, adding in <y>

o.xsd redefines n.xsd, removing <x>

Again mno.ruleml (same as the previous ab.ruleml) should not be valid
because <x> has been removed in favour of <y>.  The validation results
with XSV and Saxon are identical to before, having everything in one
<redefine> and schema.  If you think this is safer, then we can go this
route.

In case you didn't (necessarily) mean two separate schemas, I also
modified the old b.xsd to have two <redefine>s:

	<xs:redefine schemaLocation="a.xsd">
		<!-- add y to body -->
		<xs:group name="body.content">
			<xs:choice>
				<xs:group ref="body.content"/>
				<xs:element ref="y"/>				
			</xs:choice>
		</xs:group>	
	</xs:redefine>

	<xs:redefine schemaLocation="a.xsd">
		<!-- remove x from body by restriction --> 	
		<xs:group name="body.content">
			<xs:choice>
				<xs:element ref="y"/>
			</xs:choice>
		</xs:group>
	</xs:redefine>

This seems wrong to me -- wouldn't everything not redefined be included
twice?  But anyway, I thought I'd run it by the validators...

Saxon complains about the duplicate declarations, but then correctly
identifies that <x> isn't allowed in <body>:

Error on line 24 of http://www.ruleml.org/0.89/xsd/b.xsd:
  Duplicate group declaration {body.content} - previously defined on line 13 of
  http://www.ruleml.org/0.89/xsd/b.xsd
Error on line 13 of http://www.ruleml.org/0.89/xsd/b.xsd:
  Duplicate group declaration {body.content} - previously defined on line 24 of
  http://www.ruleml.org/0.89/xsd/b.xsd
Error on line 24 of http://www.ruleml.org/0.89/xsd/b.xsd:
  Duplicate group declaration {body.content} - previously defined on line 13 of
  http://www.ruleml.org/0.89/xsd/b.xsd
Finished loading schema document http://www.ruleml.org/0.89/xsd/b.xsd
Validation error on line 5 column 4 of file:/C:/docume~1/hirtled/Desktop/RuleML/
0.89/exa/ab.ruleml:
  In content of element <body>: The content model does not allow element <x> to
appear here.
  Expected: {http://www.ruleml.org/0.89/xsd}y
Validation error on line 7 column 8 of file:/C:/docume~1/hirtled/Desktop/RuleML/
0.89/exa/ab.ruleml:
  One or more validation errors were reported

As for XSV, it also correctly points out the instance error (and doesn't crash):

  <invalid char="1" code="cvc-complex-type.1.2.4" line="5"
           resource="http://www.ruleml.org/0.89/exa/ab.ruleml">
    element {http://www.ruleml.org/0.89/xsd}:x not allowed here (1) in element {
http://www.ruleml.org/0.89/xsd}:body, expecting [{http://www.ruleml.org/0.89/xsd
}:y]:

  ...
  </invalid>

So what seems wrong to me is actually better supported ... Any advice?


> Though I have to say whenever I see a schema that uses xs:redefine it
> brings back very painful memories of the struggle to get it working at
> all. My advice would be to avoid it.

I sympathize, but it seems like your hard work has paid off: in my experience,
Saxon handles <redefine> quite well.

Unfortunately, I'm not sure we can avoid using it.  The modularization
of RuleML is much like that of XHTML and, in fact, we use a similar
approach (see http://www.w3.org/TR/2004/WD-xhtml-modularization-20040218/).
We need to define a schema for each "sublanguage" of RuleML, where these
sublanguages inherit from each other -- adding new elements, removing some
or both.  Any suggestions you might have about alternatives are more than
welcome.

We're hopeful about 1.1 too, by the way.

David

-----Original Message-----
From: Michael Kay [mailto:mike@saxonica.com] 
Sent: Friday, April 01, 2005 10:34 AM
To: 'Hirtle, David'; xmlschema-dev@w3.org
Subject: RE: Both extending and restricting with <redefine>

I think this is working in Saxon more by accident than design.

I can't see a rule in Schema that bans <xs:redefine> containing two redefinitions of the same component, but there's also no statement saying what the effect should be.

Intuitively, it would be safer to go through two levels of xs:redefine.

Though I have to say whenever I see a schema that uses xs:redefine it brings back very painful memories of the struggle to get it working at all. My advice would be to avoid it. There are some potentially very nasty side-effects, for example if one stylesheet running in a web service redefines a schema, the effect is pervasive for all other subsequent transformations importing that schema namespace and using the same schema cache. Saxon doesn't allow the schema cache to contain two different components with the same name. I'm hoping the new model for component identity in 1.1 will address this problem...

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: xmlschema-dev-request@w3.org
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Hirtle, David
> Sent: 01 April 2005 15:10
> To: xmlschema-dev@w3.org
> Subject: Both extending and restricting with <redefine>
> 
> 
> (Apologies if this message is received more than once -- yesterday's 
> attempt seems to have not gone through.)
> 
> I originally thought that XML Schema didn't permit "replacing" an 
> element with another via <redefine>, i.e. both extending and 
> restricting a content model, but the spec doesn't seem to forbid doing 
> it in two steps... so I whipped up an example.  Unfortunately, I'm 
> getting mixed validation results.
> 
> a.xsd (http://www.ruleml.org/0.89/xsd/a.xsd) defines an element "body"
> which allows only the element "x".
> 
> b.xsd (http://www.ruleml.org/0.89/xsd/b.xsd) redefines "body" from 
> a.xsd, first extending it to allow a new element "y" and then 
> restricting it to disallow "x", effectively replacing "x" with "y" in 
> the content model of "body".
> 
> Assuming this is permissible in XML Schema...
> 
> ab.ruleml (http://www.ruleml.org/0.89/exa/ab.ruleml) should not be 
> valid w.r.t. b.xsd because "body" contains an "x".
> 
> XSV (web form and installation) reports no validity problems but 
> crashes.  Saxon correctly (?) identifies the problem, as appended 
> below.
> 
> So I'm left with the question: is this the correct way to "replace" an 
> element with another in a content model via <redefine> (if possible at 
> all with XML Schema)?  And what about the validators?
> 
> Thanks,
> 
> David
> 
> ***
> 
> java com.saxonica.Validate -t http://www.ruleml.org/0.89/exa/ab.ruleml
> Saxon-SA 8.3 from Saxonica
> Java version 1.5.0_01
> Processing http://www.ruleml.org/0.89/exa/ab.ruleml
> Loading schema document http://www.ruleml.org/0.89/xsd/b.xsd
> Loading schema document http://www.ruleml.org/0.89/xsd/a.xsd
> Finished loading schema document http://www.ruleml.org/0.89/xsd/a.xsd
> Finished loading schema document http://www.ruleml.org/0.89/xsd/b.xsd
> Validation error on line 5 column 4 of
> http://www.ruleml.org/0.89/exa/ab.ruleml:
> In content of element <body>: The content model does not allow element 
> <x> to appear here.
> Expected: {http://www.ruleml.org/0.89/xsd}y Validation error on line 7 
> column 8 of
> http://www.ruleml.org/0.89/exa/ab.ruleml:
> One or more validation errors were reported Validation of source 
> document failed
> 
> 

Received on Friday, 1 April 2005 18:45:18 UTC