"Type Defintion Cannot be Abstract"

Discussion in 'XML' started by Lord0, Feb 26, 2007.

  1. Lord0

    Lord0 Guest

    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
     
    Lord0, Feb 26, 2007
    #1
    1. Advertising

  2. Lord0

    Guest

    On Feb 26, 12:24 pm, "Lord0" <> 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
     
    , Feb 26, 2007
    #2
    1. Advertising

  3. Lord0

    Lord0 Guest

    > 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, Feb 26, 2007
    #3
  4. Lord0

    Lord0 Guest

    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?
     
    Lord0, Feb 26, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page