[xsde-users] No polymorphism without substitutionGroup?

Werner Haug werner.haug at agfa.com
Mon Jun 24 07:03:40 EDT 2013


Hi Boris,

I don't see, what is going wrong.
Here is an example. The two XSDs are as follows:

Msg.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:msg="XTest.XBase.Domain.Msg" xmlns:model="XTest.XBase.Domain.Model" 
xmlns:enum="XTest.XBase.Domain.Model.Enumerations" 
xmlns:xbase="XTest.XBase.Domain" targetNamespace="XTest.XBase.Domain.Msg" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:import namespace="XTest.XBase.Domain" 
schemaLocation="ValueSets.xsd"/>
        <!--Abstract message base class-->
        <xs:complexType name="MSG" abstract="true">
                <xs:sequence>
                        <xs:element name="MessageVersion" type="xs:int"/>
                        <xs:element name="SendTime" type="xs:dateTime"/>
                        <xs:element name="Sender" type="xs:string"/>
                        <xs:element name="Receiver" type="xs:string"/>
                </xs:sequence>
        </xs:complexType>
        <xs:element name="MSG" type="msg:MSG"/>
        <xs:complexType name="MSG_JOB" abstract="true">
                <xs:complexContent>
                        <xs:extension base="msg:MSG">
                                <xs:sequence>
                                        <xs:element name="JobId" 
type="xs:string"/>
                                        <xs:element name="JobSettingsId" 
type="xs:int"/>
                                </xs:sequence>
                        </xs:extension>
                </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="MSG_Prep">
                <xs:complexContent>
                        <xs:extension base="msg:MSG_JOB">
                                <xs:sequence>
                                        <xs:element name="Pressed" 
type="xbase:BoolValue"/>
                                </xs:sequence>
                        </xs:extension>
                </xs:complexContent>
        </xs:complexType>
</xs:schema>

ValueSets.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="XTest.XBase.Domain" xmlns:xs="
http://www.w3.org/2001/XMLSchema" targetNamespace="XTest.XBase.Domain" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:complexType name="BoolValue">
                <xs:complexContent>
                        <xs:extension base="DataType">
                                <xs:sequence>
                                        <xs:element name="Value" 
type="xs:boolean" nillable="true"/>
                                </xs:sequence>
                        </xs:extension>
                </xs:complexContent>
        </xs:complexType>
        <xs:complexType name="DataType">
                <xs:sequence>
                        <xs:element name="Unit" type="xs:string"/>
                        <xs:element name="IsApplicable" 
type="xs:boolean"/>
                        <xs:element name="ValidationResult" 
type="xs:string"/>
                        <xs:element name="IsRequired" type="xs:boolean"/>
                </xs:sequence>
        </xs:complexType>
</xs:schema>

To generate the code I use the following command:

xsde.exe cxx-hybrid --generate-parser --generate-serializer 
--generate-aggregate --generate-polymorphic --generate-typeinfo 
--root-element MSG --polymorphic-type MSG --output-dir src --no-long-long 
--namespace-map XTest.XBase.Domain=XTest::XBase::Domain --namespace-map 
XTest.XBase.Domain.Msg=XTest::XBase::Domain::Msg --namespace-map 
XTest.XBase.Domain.Model=XTest::XBase::Domain::Model --namespace-map 
XTest.XBase.Domain.Model.Enumerations=XTest::XBase::Domain::Model::Enumerations 
Msg.xsd ValueSets.xsd

The software (which I included in a ZIP file) produces the following 
output on serializing:

<MSG xmlns:msg="XTest.XBase.Domain.Msg" xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:type="msg:MSG_Prep">
  <msg:MessageVersion>1</msg:MessageVersion>
  <msg:SendTime>2013-06-24T11:31:45</msg:SendTime>
  <msg:Sender>Sender</msg:Sender>
  <msg:Receiver>Receiver</msg:Receiver>
  <msg:JobId>1.3.51.1234.1001.20130624.1113145</msg:JobId>
  <msg:JobSettingsId>1</msg:JobSettingsId>
  <msg:Pressed>
    <g1:Unit xmlns:g1="XTest.XBase.Domain"></g1:Unit>
    <g1:IsApplicable xmlns:g1="XTest.XBase.Domain">true</g1:IsApplicable>
    <g1:ValidationResult 
xmlns:g1="XTest.XBase.Domain"></g1:ValidationResult>
    <g1:IsRequired xmlns:g1="XTest.XBase.Domain">true</g1:IsRequired>
    <g1:Value xmlns:g1="XTest.XBase.Domain">true</g1:Value>
  </msg:Pressed>
</MSG>

When parsing the just serialized XML, I get the Parser_exception in line 
1, column 163: schema error. unexpected element encountered (which is the 
xsi:type="msg:MSG_Prep").

This is the XML I would expect:

<?xml version="1.0" encoding="utf-8"?>
<MSG xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xsi:type="MSG_Prep" 
xmlns="XTest.XBase.Domain.Msg">
  <MessageVersion>1</MessageVersion>
  <SendTime>2013-06-24T11:31:45</SendTime>
  <Sender>SPX_1</Sender>
  <JobId>1.3.51.1234.1001.20130624.1113145</JobId>
  <JobSettingsId>1</JobSettingsId>
  <Pressed>
    <IsApplicable xmlns="XTest.XBase.Domain">false</IsApplicable>
    <IsRequired xmlns="XTest.XBase.Domain">false</IsRequired>
    <Value xsi:nil="true" xmlns="XTest.XBase.Domain" />
  </Pressed>
</MSG>

Can you help?
Many thanks,
Werner

-------------- next part --------------
A non-text attachment was scrubbed...
Name: XSDTest.zip
Type: application/zip
Size: 10216 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/xsde-users/attachments/20130624/c3c5ebab/XSDTest.zip


More information about the xsde-users mailing list