Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > "Type Defintion Cannot be Abstract"

Reply
Thread Tools

"Type Defintion Cannot be Abstract"

 
 
Lord0
Guest
Posts: n/a
 
      02-26-2007
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"
xmlnssi="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"
xmlnssi="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

 
Reply With Quote
 
 
 
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      02-26-2007
On Feb 26, 12:24 pm, "Lord0" <(E-Mail Removed)> 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"
> xmlnssi="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

 
Reply With Quote
 
 
 
 
Lord0
Guest
Posts: n/a
 
      02-26-2007
> 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.


 
Reply With Quote
 
Lord0
Guest
Posts: n/a
 
      02-26-2007
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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function Declaration and Defintion Problem Amit_Basnak C++ 5 12-28-2006 09:55 AM
What would this defintion mean: int Function(class CString filename) huguogang@gmail.com C++ 4 10-02-2006 07:31 AM
XML defintion yasar.khan@gmail.com XML 3 08-01-2006 08:04 AM
Different TD style defintion per table? Bardo HTML 3 07-11-2004 12:11 PM
XSD document for XSD defintion Rick Razzano XML 1 09-26-2003 12:41 AM



Advertisments