Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   "Type Defintion Cannot be Abstract" (http://www.velocityreviews.com/forums/t392884-type-defintion-cannot-be-abstract.html)

Lord0 02-26-2007 10:24 AM

"Type Defintion Cannot be Abstract"
 
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.lepin@ctncorp.com 02-26-2007 11:25 AM

Re: "Type Defintion Cannot be Abstract"
 
On Feb 26, 12:24 pm, "Lord0" <l...@hotmail.co.uk> wrote:
> 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.)

--
Pavel Lepin


Lord0 02-26-2007 12:05 PM

Re: "Type Defintion Cannot be Abstract"
 
> 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.



Lord0 02-26-2007 12:20 PM

Re: "Type Defintion Cannot be Abstract"
 
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?



All times are GMT. The time now is 04:14 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.