"Type Defintion Cannot be Abstract"

L

Lord0

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
 
P

p.lepin

I am trying to implement variable content containers
using an abstract type and type substitution.
[...]

<?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 believe XML Schema Part 0: Primer SE, 4.7 explains why
this doesn't work. There doesn't seem to be anything to
help you achieve what you want, though. (I doubt you would
want to use xsi:type, and there doesn't seem to be any
other way to make it work.)
 
L

Lord0

I believe XML Schema Part 0: Primer SE, 4.7 explains why this doesn't work

Thanks for the link - it was very useful.
. There doesn't seem to be anything to
help you achieve what you want, though. (I doubt you would
want to use xsi:type, and there doesn't seem to be any
other way to make it work.)


xsi:type does indeed allow it to work! But you're right - I wouldn't
want to use it.
 
L

Lord0

Looking at the doc mentioned above there are examples such as

"<complexType name="US-Address" base="ipo:Address"
derivedBy="extension">"

However according to my parser "base" and "derivedBy" are not valid
attributes for element complexType.

Thoughts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top