Connecting Tech Pros Worldwide Forums | Help | Site Map

substitution groups problem.

Newbie
 
Join Date: Nov 2005
Posts: 2
#1: Nov 12 '05
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:
Expand|Select|Wrap|Line Numbers
  1. ********************************************************************
  2. XX1.XSD:
  3. ********************************************************************
  4. <?xml version="1.0" encoding="ISO-8859-1"?>
  5. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:PARTICIPATION="Participation" targetNamespace="Participation">
  6. <!-- ================================================= -->
  7. <!-- Package: Participation -->
  8. <!-- ================================================= -->
  9. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  10. <!-- Class: <<ST>> SignatureString -->
  11. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  12. <xs:element name="signatureString" type="PARTICIPATION:SignatureString" substitutionGroup="PARTICIPATION:signatureText"/>
  13. <xs:complexType name="SignatureString">
  14. <xs:complexContent>
  15. <xs:extension base="PARTICIPATION:SignatureText">
  16. <xs:attribute name="value" type="xs:string" use="required"/>
  17. </xs:extension>
  18. </xs:complexContent>
  19. </xs:complexType>
  20. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  21. <!-- Class: SignatureText -->
  22. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  23. <xs:element name="signatureText" type="PARTICIPATION:SignatureText" abstract="true"/>
  24. <xs:complexType name="SignatureText" abstract="true"/>
  25. </xs:schema>
  26. ***********************************************************************
  27. YY1.xsd:
  28. ***********************************************************************
  29. <?xml version="1.0" encoding="ISO-8859-1"?>
  30. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:CM3202="Common3202" xmlns:PARTICIPATION="Participation" targetNamespace="Common3202">
  31. <xs:import namespace="Participation" schemaLocation="Datatypes3203/RDT/Participation.xsd"/>
  32. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  33. <!-- Class: <<Participation>> PractitionerParticipation -->
  34. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  35. <xs:element name="practitionerParticipation" type="CM3202:PractitionerParticipation" abstract="true"/>
  36. <xs:complexType name="PractitionerParticipation" abstract="true">
  37. <xs:sequence>
  38. <!--xs:element name="signatureText" type="PARTICIPATION:SignatureText" minOccurs="0"/-->
  39. <xs:element ref="PARTICIPATION:signatureText"/>
  40. </xs:sequence>
  41. </xs:complexType>
  42. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  43. <!-- Class: <<Participation>> Author -->
  44. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  45. <xs:element name="author" type="CM3202:Author" substitutionGroup="CM3202:practitionerParticipation"/>
  46. <xs:complexType name="Author">
  47. <xs:complexContent>
  48. <xs:extension base="CM3202:PractitionerParticipation"/>
  49. </xs:complexContent>
  50. </xs:complexType>
  51.  
  52. </xs:schema>
  53. ********************************************************************
  54. ZZ1.xsd
  55. *******************************************************************
  56. <?xml version="1.0" encoding="ISO-8859-1"?>
  57. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:VS3203="VitalSigns3203" xmlns:CM3202="Common3202" targetNamespace="VitalSigns3203">
  58. <xs:import namespace="Common3202" schemaLocation="Common3202.xsd"/>
  59. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  60. <!-- Class: <<Observation>> VitalSignsObservationEvent -->
  61. <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  62. <xs:element name="vitalSignsObservationEvent" type="VS3203:VitalSignsObservationEvent"/>
  63. <xs:complexType name="VitalSignsObservationEvent">
  64. <xs:sequence>
  65. <xs:element name="author" type="CM3202:Author" minOccurs="0">
  66. </xs:element>
  67. </xs:sequence>
  68. </xs:complexType>
  69. </xs:schema>
  70.  

Newbie
 
Join Date: Nov 2005
Posts: 2
#2: Nov 17 '05

re: substitution groups problem.


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.
Reply