I am trying to implement variable content containers using an abstract
type and type substitution. My schema is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:this="this"
targetNamespace="this" elementFormDefault="qualified">
<complexType name="abstractAnswerType" abstract="true"/>
<complexType name="yesWithDescType">
<complexContent>
<extension base="this:abstractAnswerType">
<sequence>
<element name="description" type="string" />
</sequence>
<attribute name="answer" type="string" fixed="yes"
use="required"/>
</extension>
</complexContent>
</complexType>
<complexType name="noType">
<complexContent>
<extension base="this:abstractAnswerType">
<attribute name="answer" type="string" fixed="no"
use="required"/>
</extension>
</complexContent>
</complexType>
<element name="root">
<complexType>
<sequence>
<element name="question" type="this:abstractAnswerType" />
</sequence>
</complexType>
</element>
</schema>
When I generate a document using my IDE (oXygen), the following
instance document is created:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="this"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="this file:/C:/variableContent.xsd">
<question/>
</root>
Which is not valid as "Type Defintion Cannot be Abstract for element
question". I thought my IDE had just failed to perform the type
substition but when I manually create the following instance document:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="this"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="this file:/C:/variableContent.xsd">
<question answer="yes">
<description>Some text</description>
</question>
</root>
This too is not valid because "Attribute 'answer' is not allowed to
appear in element 'question'." and "Element 'question' must have no
character or element information item [children], because the type's
content type is empty.". So again it appears as if the validator is
failing to realise that "yesWithDescType" is a valid substitution for
"abstractAnswerType".
I should mention that I can get this to work when I use element
substitution instead of type substitution.
Any thoughts? I feel I am missing something obvious.
Cheers
Lord0