www.webdeveloper.com
Results 1 to 2 of 2

Thread: xsd substitution groups

  1. #1
    Join Date
    Nov 2005
    Posts
    2

    xsd substitution groups

    I am new to xml/xsd world.

    I have used substitution groups 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 xsds instance document.
    The 3 xsds and the xml file code is below. The files related to A.1 are XX1.xsd and YY1.xsd.
    The files related to A.2 are ZZ1.xsd and ZZ1.xml.

    XX1.xsd has a complex abstract type. It is imported and a referenced as the data type of an abstract element in YY1.xsd.
    YY1.xsd is imported to ZZ1.xsd.

    The validation of xml file generated from ZZ1.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

    Any help in this regard at the earliest is highly appreciated.

    B) Also I want to know the following:
    1) The differences between element and complex type being declared as abstract in case of substitution groups.
    2) Can xsi:type usage allowed in instance documents in case of substitution groups.


    The code of each xsd file is as follows:
    ************************************************** ******************
    XX1.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>
    ************************************************** *********************
    YY1.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 ractitionerParticipation"/>
    <xs:complexType name="Author">
    <xs:complexContent>
    <xs:extension base="CM3202:PractitionerParticipation"/>
    </xs:complexContent>
    </xs:complexType>

    </xs:schema>
    ************************************************** ******************
    ZZ1.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>
    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="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>
    ************************************************** *********************
    YY1.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 ractitionerParticipation"/>
    <xs:complexType name="Author">
    <xs:complexContent>
    <xs:extension base="CM3202:PractitionerParticipation"/>
    </xs:complexContent>
    </xs:complexType>

    </xs:schema>
    ************************************************** ******************
    ZZ1.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>
    ************************************************** ******************
    ZZ1.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>

  2. #2
    Join Date
    Nov 2005
    Posts
    2
    Hi all,

    More info. regarding this problem: The error occurs when each xsd has a different namespace and thus has problem with imports.
    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.
    Thus any input in this regard is highly appreciated.

    Thanks in advance.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles