Re: xsd substitution groups weird problem

Hi,

On Thu, 2005-11-17 at 08:00 -0800, sreedevi crk wrote:
> Hi Kasimier,
>  
> Thanks for the reply. 
> VitalSigns.xml validated fine by adding namespace as per your
> suggestion.
>  But in my real world scenario, we have lot of levels of substitution
> groups and manual changes to the instance documents will be very hard.
> Thus wondering if there is any solution as this seems to be a bug in
> xsd/xml validation (i.e problem with namespace recognition in case of
> import statements in case of substitution groups two levels deep).
> Any help is highly appreciated.

I finaly found some time to test your scenario.

I don't think this is a bug related to validation; I think it's a
bug in the schema or in the instance document.
As already said, the element "signatureString" is declared in the
schema to be in the namespace "Participation". It obviously does
not match an element in no namespace. In order to create a schema
that eats the "signatureString" element in no namespace, you need
to declare such an element and put it in the substitution group
of the abstract "{Participation}signatureText" element declaration.

To be valid, I changed your scenario in the following way:

In "VitalSigns3203.xml":
- the value of xsi:schemaLocation is missing the namespace part

In "VitalSigns3203.xsd":
- The element "author" is either in the wrong namespace, or the
 schema missed to _reference_ the declaration of "{Common3202}author".
 I changed...
   <xs:element name="author" type="CM3202:Author" minOccurs="0"/>	
 ... to ...
   <xs:element ref="CM3202:author" minOccurs="0"/>
 ... but seeing that in "Common3202.xsd" you put "{Common3202}author"
 in the subtitution group of "{Common3202}practitionerParticipation",
 I guess that the real intention was to declare:
   <xs:element ref="CM3202:practitionerParticipation" minOccurs="0"/>

In "Common3202.xsd":
 - The value of the substitutionGroup attribute was mangled in your
   mail (at least for me):
  <xs:element name="author" type="CM3202:Author"
    substitutionGroup="CM3202 ractitionerParticipation"/>
   I changed the value to "CM3202:practitionerParticipation"

In "Participation.xsd":
  - Removed the declaration of the element "signatureString" and
    imported it from an additional schema with no targetNamespace.


The results of those changes:

The instance is valid according to Xerces-J 2.7.1, Saxon 8.5.1,
XSV 2.10 and Libxml2 2.6.22.
IBM's SQC and MSXML 4.0 SP2 bark about the schemata.
SQC reports: "VitalSigns3203 is not a valid absolute URI. No scheme
found in URI."
Seems like SQC (and maybe XSML) does not support 'wanna-be' URIs.

The new scenario:

VitalSigns3203.xml
------------------
<VS3203:vitalSignsObservationEvent
	xmlns:VS3203="VitalSigns3203"
	xmlns:CM3202="Common3202"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="VitalSigns3203 VitalSigns3203.xsd">
	<CM3202:author>
		<signatureString value="String"/>
	</CM3202:author>
</VS3203:vitalSignsObservationEvent>

VitalSigns3203.xsd
------------------
<xs:schema targetNamespace="VitalSigns3203"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:VS3203="VitalSigns3203"
	xmlns:CM3202="Common3202">

	<xs:import namespace="Common3202"
          schemaLocation="Common3202.xsd"/>

	<xs:element name="vitalSignsObservationEvent"
          type="VS3203:VitalSignsObservationEvent"/>

	<xs:complexType name="VitalSignsObservationEvent">
		<xs:sequence>			
			<!--xs:element name="author"
 type="CM3202:Author" minOccurs="0"/-->
			<!--xs:element ref="CM3202:author"/-->
			<xs:element
                          ref="CM3202:practitionerParticipation"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>

Common3202.xsd
--------------
<xs:schema targetNamespace="Common3202"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:CM3202="Common3202"
	xmlns:PARTICIPATION="Participation">

	<xs:import namespace="Participation"
schemaLocation="Participation.xsd"/>	
	
	<xs:element name="practitionerParticipation"
		type="CM3202:PractitionerParticipation"
		abstract="true"/>

	<xs:complexType name="PractitionerParticipation"
		abstract="true">
		<xs:sequence>
			<xs:element ref="PARTICIPATION:signatureText" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>

	<xs:element name="author"
		type="CM3202:Author"
		substitutionGroup="CM3202:practitionerParticipation"/>
	<!-- substitutionGroup="CM3202 ractitionerParticipation" -->

	<xs:complexType name="Author">
		<xs:complexContent>
			<xs:extension base="CM3202:PractitionerParticipation"/>
		</xs:complexContent>
	</xs:complexType>

</xs:schema>

Participation.xsd
-----------------
<xs:schema targetNamespace="Participation"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:PARTICIPATION="Participation">

	<xs:import schemaLocation="Participation-B.xsd"/>

	<xs:element name="signatureText"
		type="PARTICIPATION:SignatureText"
		abstract="true"/>
	<xs:complexType name="SignatureText" abstract="true"/>

</xs:schema>

Participation-B.xsd
-------------------
<xs:schema
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:PARTICIPATION="Participation">

	<!-- Concrete declarations in no namespace
	  for "{Participation}signatureText" -->

	<xs:import namespace="Participation"/>
	
	<xs:element name="signatureString" type="SignatureString"
		substitutionGroup="PARTICIPATION:signatureText"/>

	<xs:complexType name="SignatureString">
		<xs:complexContent>
			<xs:extension base="PARTICIPATION:SignatureText">
				<xs:attribute name="value"
					type="xs:string" use="required"/>
			</xs:extension>
		</xs:complexContent>
	</xs:complexType>
</xs:schema>

Regards,

Kasimier

Received on Thursday, 17 November 2005 17:22:07 UTC