You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Jozef Aerts - Comp.Chem.Cons. - XML4Pharma" <co...@hotmail.com> on 2006/10/27 10:10:16 UTC

Problem with xs:choice in xs:redefine

Problem: xs:choice in xs:redefine

I have a base schema in one file with the following definition:

<xs:complexType name="ODMcomplexTypeDefinition-Protocol">
          <xs:sequence>
           		<xs:element      ref="StudyEventRef" maxOccurs="unbounded"/>
            	<xs:group        ref="ProtocolElementExtension" minOccurs="0" 
maxOccurs="unbounded"/>
          </xs:sequence>
          <xs:attributeGroup ref="ProtocolAttributeExtension"/>
</xs:complexType>

<!-- empty group for extensions to the Protocol element -->
<xs:group name="ProtocolElementExtension">
           <xs:sequence/>
</xs:group>

<xs:element name="Protocol" type="ODMcomplexTypeDefinition-Protocol">


Now I defined an extension XML-schema (in another namespace).
The incorporation of the extension schema (TDM_Part1_extension.xsd) into the 
base schema is done by:

	<xs:redefine schemaLocation="ODM1-2-1.xsd">
		<xs:complexType name="ODMcomplexTypeDefinition-Protocol">
			<xs:complexContent>
				<xs:restriction base="ODMcomplexTypeDefinition-Protocol">
					<xs:choice>
						<xs:sequence>
							<xs:element ref="StudyEventRef" maxOccurs="unbounded"/>
						</xs:sequence>
						<xs:sequence>
							<xs:element ref="tdm:TrialArm" minOccurs="0" maxOccurs="unbounded"/>
							<xs:element ref="tdm:TrialSegment" minOccurs="0" 
maxOccurs="unbounded"/>
							<xs:element ref="tdm:TrialElement" minOccurs="0" 
maxOccurs="unbounded"/>
							<xs:element ref="tdm:TrialEpoch" minOccurs="0" 
maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:choice>
					<!-- keep the attributes -->
					<xs:attributeGroup ref="ProtocolAttributeExtension"/>
				</xs:restriction>
			</xs:complexContent>
		</xs:complexType>
	</xs:redefine>

What I mean to accomplish is that in the extended schema it is defined that 
the element Protocol can EITHER have one or more StudyEventRef subelements 
OR one zero or more of the tdm:TrialArm etc.. elements.

This seems to work fine (I can correctly validate instance files against the 
schema), until I try to compile the schema with XMLBeans (v.2.2.0, Xerces 
2.6.2)

In the Java code I do the following:
	List sdocs = new ArrayList();
	schemaInformation = new SchemaInformation();
	XmlOptions xmloptions = new XmlOptions();
	xmloptions.setLoadLineNumbers().setLoadMessageDigest();
	xmloptions.setCompileDownloadUrls(); // allow compilation of schemas that 
are imported/included using a URL
	// xmloptions.setSaveNamespacesFirst();  // just trying, 30.8.2005
	try {
		sdocs.add(XmlObject.Factory.parse(schemaFile, xmloptions));
	} catch (Exception e) {
		System.err.println( schemaFile + " not loadable: " + e );
		OK = false;
	}
	XmlObject[] schemas = (XmlObject[])sdocs.toArray(new XmlObject[0]);
	//System.out.println("length of schemas = " + schemas.length);  // should 
give 1 if only one schema was compiled
	XmlObject mySchema = schemas[0];
	System.out.println("Schema validation gives : " + mySchema.validate());

This does not give any problems. The schema validates fine.
Then I try to compile ...

	XmlObject[] schemas = (XmlObject[])sdocs.toArray(new XmlObject[0]);
	SchemaTypeLoader sLoader = null;
	Collection compErrors = new ArrayList();
	XmlOptions schemaOptions = new XmlOptions();
	schemaOptions.setCompileDownloadUrls(); // allow import of other schemas 
using URLs
	schemaOptions.setErrorListener(compErrors);
	//schemaOptions.setSaveAggressiveNamespaces();
	if (downloadURLs) schemaOptions.setCompileDownloadUrls();
	//SchemaTypeSystem sts = null;
	try {
		if (schemas != null && schemas.length > 0) sts = 
XmlBeans.compileXsd(schemas, sLoader, schemaOptions);
	} catch (Exception e) {
		...

The errors I get are:

Schema invalid:
Loading referenced file 
file:/C:/Protocol_ODM/TDM_Part1/xmldsig-core-schema.xsd
Loading referenced file 
file:/C:/Protocol_ODM/TDM_Part1/TDM_Part1_extension.xsd
Loading referenced file file:/C:/Protocol_ODM/TDM_Part1/TDM_Part1_ns.xsd
Loading referenced file file:/C:/Protocol_ODM/TDM_Part1/ODM1-2-1.xsd
Loading referenced file file:/C:/Protocol_ODM/TDM_Part1/xlink.xsd
Loading referenced file 
file:/C:/Protocol_ODM/TDM_Part1/ODM1-2-1-foundation.xsd
C:\Protocol_ODM\TDM_Part1\TDM_Part1_extension.xsd:19:3:
error: cos-particle-restrict.2: Invalid Restriction.
The derived content model <element 
name="StudyEventRef@http://www.cdisc.org/ns/odm/v1.2"> cannot restrict base 
content model <choice>.

So I presume I did something wrong within the <xs:redefine>, maybe that it 
is not allowed to have <xs:choice> within <xs:restriction> ?
Can someone explain one is wrong with my schema, and how it can be improved 
so that what is meant to be accomplished is still OK ?

Many thanks in advance

Jozef

_________________________________________________________________
Play online games with your friends with Messenger 
http://www.join.msn.com/messenger/overview


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Problem with xs:choice in xs:redefine

Posted by Radu Preotiuc-Pietro <ra...@bea.com>.
Redefine plays no role in this scenario.
You are trying to restrict a content model of

StudyEventRef+

with

StudyEventRef+|tdm:TrialArm....

This is not allowed. The restriction must validate a subset of the
documents validated by the base type.

As far as being able to validate documents ok, I think maybe the
validator doesn't have access to the redefining Schema or something,
validation should of course fail.

Hope this helps,
Radu

On Fri, 2006-10-27 at 08:10 +0000, Jozef Aerts - Comp.Chem.Cons. -
XML4Pharma wrote:
> Problem: xs:choice in xs:redefine
> 
> I have a base schema in one file with the following definition:
> 
> <xs:complexType name="ODMcomplexTypeDefinition-Protocol">
>           <xs:sequence>
>            		<xs:element      ref="StudyEventRef" maxOccurs="unbounded"/>
>             	<xs:group        ref="ProtocolElementExtension" minOccurs="0" 
> maxOccurs="unbounded"/>
>           </xs:sequence>
>           <xs:attributeGroup ref="ProtocolAttributeExtension"/>
> </xs:complexType>
> 
> <!-- empty group for extensions to the Protocol element -->
> <xs:group name="ProtocolElementExtension">
>            <xs:sequence/>
> </xs:group>
> 
> <xs:element name="Protocol" type="ODMcomplexTypeDefinition-Protocol">
> 
> 
> Now I defined an extension XML-schema (in another namespace).
> The incorporation of the extension schema (TDM_Part1_extension.xsd) into the 
> base schema is done by:
> 
> 	<xs:redefine schemaLocation="ODM1-2-1.xsd">
> 		<xs:complexType name="ODMcomplexTypeDefinition-Protocol">
> 			<xs:complexContent>
> 				<xs:restriction base="ODMcomplexTypeDefinition-Protocol">
> 					<xs:choice>
> 						<xs:sequence>
> 							<xs:element ref="StudyEventRef" maxOccurs="unbounded"/>
> 						</xs:sequence>
> 						<xs:sequence>
> 							<xs:element ref="tdm:TrialArm" minOccurs="0" maxOccurs="unbounded"/>
> 							<xs:element ref="tdm:TrialSegment" minOccurs="0" 
> maxOccurs="unbounded"/>
> 							<xs:element ref="tdm:TrialElement" minOccurs="0" 
> maxOccurs="unbounded"/>
> 							<xs:element ref="tdm:TrialEpoch" minOccurs="0" 
> maxOccurs="unbounded"/>
> 						</xs:sequence>
> 					</xs:choice>
> 					<!-- keep the attributes -->
> 					<xs:attributeGroup ref="ProtocolAttributeExtension"/>
> 				</xs:restriction>
> 			</xs:complexContent>
> 		</xs:complexType>
> 	</xs:redefine>
> 
> What I mean to accomplish is that in the extended schema it is defined that 
> the element Protocol can EITHER have one or more StudyEventRef subelements 
> OR one zero or more of the tdm:TrialArm etc.. elements.
> 
> This seems to work fine (I can correctly validate instance files against the 
> schema), until I try to compile the schema with XMLBeans (v.2.2.0, Xerces 
> 2.6.2)
> 
> In the Java code I do the following:
> 	List sdocs = new ArrayList();
> 	schemaInformation = new SchemaInformation();
> 	XmlOptions xmloptions = new XmlOptions();
> 	xmloptions.setLoadLineNumbers().setLoadMessageDigest();
> 	xmloptions.setCompileDownloadUrls(); // allow compilation of schemas that 
> are imported/included using a URL
> 	// xmloptions.setSaveNamespacesFirst();  // just trying, 30.8.2005
> 	try {
> 		sdocs.add(XmlObject.Factory.parse(schemaFile, xmloptions));
> 	} catch (Exception e) {
> 		System.err.println( schemaFile + " not loadable: " + e );
> 		OK = false;
> 	}
> 	XmlObject[] schemas = (XmlObject[])sdocs.toArray(new XmlObject[0]);
> 	//System.out.println("length of schemas = " + schemas.length);  // should 
> give 1 if only one schema was compiled
> 	XmlObject mySchema = schemas[0];
> 	System.out.println("Schema validation gives : " + mySchema.validate());
> 
> This does not give any problems. The schema validates fine.
> Then I try to compile ...
> 
> 	XmlObject[] schemas = (XmlObject[])sdocs.toArray(new XmlObject[0]);
> 	SchemaTypeLoader sLoader = null;
> 	Collection compErrors = new ArrayList();
> 	XmlOptions schemaOptions = new XmlOptions();
> 	schemaOptions.setCompileDownloadUrls(); // allow import of other schemas 
> using URLs
> 	schemaOptions.setErrorListener(compErrors);
> 	//schemaOptions.setSaveAggressiveNamespaces();
> 	if (downloadURLs) schemaOptions.setCompileDownloadUrls();
> 	//SchemaTypeSystem sts = null;
> 	try {
> 		if (schemas != null && schemas.length > 0) sts = 
> XmlBeans.compileXsd(schemas, sLoader, schemaOptions);
> 	} catch (Exception e) {
> 		...
> 
> The errors I get are:
> 
> Schema invalid:
> Loading referenced file 
> file:/C:/Protocol_ODM/TDM_Part1/xmldsig-core-schema.xsd
> Loading referenced file 
> file:/C:/Protocol_ODM/TDM_Part1/TDM_Part1_extension.xsd
> Loading referenced file file:/C:/Protocol_ODM/TDM_Part1/TDM_Part1_ns.xsd
> Loading referenced file file:/C:/Protocol_ODM/TDM_Part1/ODM1-2-1.xsd
> Loading referenced file file:/C:/Protocol_ODM/TDM_Part1/xlink.xsd
> Loading referenced file 
> file:/C:/Protocol_ODM/TDM_Part1/ODM1-2-1-foundation.xsd
> C:\Protocol_ODM\TDM_Part1\TDM_Part1_extension.xsd:19:3:
> error: cos-particle-restrict.2: Invalid Restriction.
> The derived content model <element 
> name="StudyEventRef@http://www.cdisc.org/ns/odm/v1.2"> cannot restrict base 
> content model <choice>.
> 
> So I presume I did something wrong within the <xs:redefine>, maybe that it 
> is not allowed to have <xs:choice> within <xs:restriction> ?
> Can someone explain one is wrong with my schema, and how it can be improved 
> so that what is meant to be accomplished is still OK ?
> 
> Many thanks in advance
> 
> Jozef
> 
> _________________________________________________________________
> Play online games with your friends with Messenger 
> http://www.join.msn.com/messenger/overview
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org