kollareddy
Programmer
Hi all,
I am new to xml/xsd world. I want to know the differences between complex type and element being abstract and if both can be declared so, in case of substitution goups.Also can xsi:type usuage allowes in instance doucments in case of substitution goups.
I tried using abstarct complex type/element with substitution groups and I attached the code below.
In XX1.xsd which is imported and a reference to complex abstract type is made in YY1.xsd. But the instance document validation of ZZ1.xsd fails when YY1.xsd is imported to ZZ1.xsd and when the complex type is referenced. XMLSpy and Xerces give the same error as follows:This file is not valid. Unexpected element'signatureString' in element author. Expected signatureString,signatureText.
Please let me know what is wrong with the code and any help in this regard at the earliest is highly appeciated.
The code of each xsd file is as follows:
************************************************** ******************
XX1.XSD:
************************************************** ******************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs=" xmlns
ARTICIPATION="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>
************************************************** *********************
YY1.xsd:
************************************************** *********************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs=" xmlns:CM3202="Common3202" xmlns
ARTICIPATION="Participation" targetNamespace="Common3202">
<xs:import namespace="Participation" schemaLocation="Datatypes3203/RDT/Participation.xsd"/>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Class: <<Participation>> PractitionerParticipation -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xs:element name="practitionerParticipation" type="CM3202
ractitionerParticipation" 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="CM3202ractitionerParticipation"/>
<xs:complexType name="Author">
<xs:complexContent>
<xs:extension base="CM3202
ractitionerParticipation"/>
</xs:complexContent>
</xs:complexType>
</xs:schema>
************************************************** ******************
ZZ1.xsd
************************************************** *****************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs=" 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>
I am new to xml/xsd world. I want to know the differences between complex type and element being abstract and if both can be declared so, in case of substitution goups.Also can xsi:type usuage allowes in instance doucments in case of substitution goups.
I tried using abstarct complex type/element with substitution groups and I attached the code below.
In XX1.xsd which is imported and a reference to complex abstract type is made in YY1.xsd. But the instance document validation of ZZ1.xsd fails when YY1.xsd is imported to ZZ1.xsd and when the complex type is referenced. XMLSpy and Xerces give the same error as follows:This file is not valid. Unexpected element'signatureString' in element author. Expected signatureString,signatureText.
Please let me know what is wrong with the code and any help in this regard at the earliest is highly appeciated.
The code of each xsd file is as follows:
************************************************** ******************
XX1.XSD:
************************************************** ******************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs=" xmlns
<!-- ================================================= -->
<!-- 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>
************************************************** *********************
YY1.xsd:
************************************************** *********************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs=" xmlns:CM3202="Common3202" xmlns
<xs:import namespace="Participation" schemaLocation="Datatypes3203/RDT/Participation.xsd"/>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Class: <<Participation>> PractitionerParticipation -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xs:element name="practitionerParticipation" type="CM3202
<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="CM3202ractitionerParticipation"/>
<xs:complexType name="Author">
<xs:complexContent>
<xs:extension base="CM3202
</xs:complexContent>
</xs:complexType>
</xs:schema>
************************************************** ******************
ZZ1.xsd
************************************************** *****************
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs=" 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>