Hi all,
I posted this issue in all xml/xsd forums, but no solution.Thus trying here.
I am trying to solve the problem of validating instance documents of the substitution groups (with abstract elements and complex types) which is more than one level deep.
Details and the xsds are as follows:
A.1) I tried using abstract complex type/element with substitution groups that are two levels deep.
A.2) But I am unable to validate the calling xsd’s instance document.
The 3 xsds and the xml file code is below. The files related to A.1 are Participation.xsd and Commons3202.xsd.
The files related to A.2 are VitalSigns3203.xsd and VitalSigns3203.xml.
Participation.xsd has a complex abstract type. It is imported and a referenced as the data type of an abstract element in Commons3202.xsd.
Commons3202.xsd is imported to VitalSigns3203.xsd.
The validation of xml file generated from VitalSigns3203.xsd fails giving the below error:
cvc-complex-type.2.4.a: Invalid
content was found starting with element 'signature String'. One of '{"Participation":signatureText}' is expected.
The above error is reproducible in xmlspy, stylus, xerces and jaxp 1.1.
During futher investigation, I found that the error occurs when each xsd involving substitution groups has a different namespace and thus has problem with import statement. In other words if I flatten all the xsds that have substitution groups, it works fine.
Also it works fine when all the xsds are in the same namespace and when include statement is used. But I want to avoid name collisions by using different namespaces. Does it mean that it is a bug in xml schemas itself??
Any help in this regard at the earliest is highly appreciated.
The code of each xsd file is as follows:
************************************************** ******************
Paticipation.xsd:
************************************************** ******************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:PARTICIPATION="Participation" targetNamespace="Participation">
<!-- ================================================= -->
<!-- Package: Participation -->
<!-- ================================================= -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Class: <<ST>> SignatureString -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xs:element name="signatureString" type="PARTICIPATION: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>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Class: SignatureText -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xs:element name="signatureText" type="PARTICIPATION:SignatureText" abstract="true"/>
<xs:complexType name="SignatureText" abstract="true"/>
</xs:schema>
************************************************** *********************
Common3202.xsd:
************************************************** *********************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:CM3202="Common3202" xmlns:PARTICIPATION="Participation" targetNamespace="Common3202">
<xs:import namespace="Participation" schemaLocation="Datatypes3203/RDT/Participation.xsd"/>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Class: <<Participation>> PractitionerParticipation -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xs:element name="practitionerParticipation" type="CM3202:PractitionerParticipation" abstract="true"/>
<xs:complexType name="PractitionerParticipation" abstract="true">
<xs:sequence>
<!--xs:element name="signatureText" type="PARTICIPATION:SignatureText" minOccurs="0"/-->
<xs:element ref="PARTICIPATION:signatureText"/>
</xs:sequence>
</xs:complexType>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Class: <<Participation>> Author -->
<!--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xs:element name="author" type="CM3202:Author" substitutionGroup="CM3202: PractitionerParticipation"/>
<xs:complexType name="Author">
<xs:complexContent>
<xs:extension base="CM3202:PractitionerParticipation"/>
</xs:complexContent>
</xs:complexType>
</xs:schema>
************************************************** ******************
VitalSigns3203.xsd
************************************************** *****************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:VS3203="VitalSigns3203" xmlns:CM3202="Common3202" targetNamespace="VitalSigns3203">
<xs:import namespace="Common3202" schemaLocation="Common3202.xsd"/>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Class: <<Observation>> VitalSignsObservationEvent -->
<!--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xs:element name="vitalSignsObservationEvent" type="VS3203:VitalSignsObservationEvent"/>
<xs:complexType name="VitalSignsObservationEvent">
<xs:sequence>
<xs:element name="author" type="CM3202:Author" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
************************************************** ******************
VitalSigns3203.xml
************************************************** *****************
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2005 rel. 3 U (http://www.altova.com)-->
<VS3203:vitalSignsObservationEvent xmlns:VS3203="VitalSigns3203" xmlns:CM3202="Common3202" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="VitalSigns3203:\DOCUME~1\vhaislkondas\MYDOCU~1\VHIM3200\VitalSigns3203.xsd">
<CM3202:author>
<signatureString value="String"/> //shows ERROR at this line.
</CM3202:author>
</VS3203:vitalSignsObservationEvent>