Element + complextype name in xml schema

Discussion in 'XML' started by Nicolas Mailhot, Apr 8, 2005.

  1. Hi,

    I've been sent an xsd that uses the following construct :

    <xsi:element name="foo">
    <xsi:complexType name="foo">

    Is this something allowed ? I couldn't find anything that said it's
    wrong, but at the same time I have an xml parser that chokes on it and
    none of the public xsd examples I've ever seen used it. I'd like to
    know if I should file a bug on the parser or if I can tell the people
    that send me the schema their definition does not fly.

    I've little experience on xml schemas so far though it looks like I'm
    up for an accelerated course.

    Regards,

    --
    Nicolas Mailhot
    Nicolas Mailhot, Apr 8, 2005
    #1
    1. Advertising

  2. Nicolas Mailhot wrote:


    > I've been sent an xsd that uses the following construct :
    >
    > <xsi:element name="foo">
    > <xsi:complexType name="foo">
    >
    > Is this something allowed ? I couldn't find anything that said it's
    > wrong, but at the same time I have an xml parser that chokes on it and
    > none of the public xsd examples I've ever seen used it. I'd like to
    > know if I should file a bug on the parser or if I can tell the people
    > that send me the schema their definition does not fly.


    I think it is allowed to have types and elements with the same name as
    different scopes are used for type names and for element names.
    I am however not sure it makes sense to have a name attribute on that
    anonymous type nested inside the element declaration, usually if you
    want to name a type you use
    <xsd:complexType name="foo">
    ...
    </xsd:complexType>

    <xsd:element name="foo" type="foo" />


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Apr 8, 2005
    #2
    1. Advertising

  3. On Fri, 08 Apr 2005 17:36:33 +0200, Martin Honnen wrote:

    > I am however not sure it makes sense to have a name attribute on that
    > anonymous type nested inside the element declaration,


    Sure, if it made sense it'd be used more often. But before I complain
    about it I'd like to be dead-sure it's not allowed - if it were my own xsd
    this would be different.

    I _so_ wish there was an w3c validator service for xsds. The specs
    themselves are sometimes not readable by mere mortals, and who's to say
    one third-party tool is more right than another ?

    Regards

    --
    Nicolas Mailhot
    Nicolas Mailhot, Apr 8, 2005
    #3
  4. Nicolas Mailhot wrote:


    > But before I complain
    > about it I'd like to be dead-sure it's not allowed - if it were my own xsd
    > this would be different.


    I have had a look through
    http://www.w3.org/TR/xmlschema-1/#Complex_Type_Definitions
    and can't find anything in there suggesting that the name attribute on
    xs:complexType is only allowed in certain cases or disallowed in other
    cases.

    However both Xerces Java as well as MSXML complain about that case and
    indeed the schema for schemas says for topLevelComplexType

    <xs:complexType name="topLevelComplexType">
    <xs:complexContent>
    <xs:restriction base="xs:complexType">
    <xs:sequence>
    <xs:element ref="xs:annotation" minOccurs="0"/>
    <xs:group ref="xs:complexTypeModel"/>
    </xs:sequence>
    <xs:attribute name="name" type="xs:NCName" use="required"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:restriction>
    </xs:complexContent>

    so there the name attribute is required while for localComplexType

    <xs:complexType name="localComplexType">
    <xs:complexContent>
    <xs:restriction base="xs:complexType">
    <xs:sequence>
    <xs:element ref="xs:annotation" minOccurs="0"/>
    <xs:group ref="xs:complexTypeModel"/>
    </xs:sequence>
    <xs:attribute name="name" use="prohibited"/>
    <xs:attribute name="abstract" use="prohibited"/>
    <xs:attribute name="final" use="prohibited"/>
    <xs:attribute name="block" use="prohibited"/>
    <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:restriction>
    </xs:complexContent>
    </xs:complexType>

    the name attribute is prohibited.

    So you should complain if someone sends you a schema with
    <xs:element name="element-name">
    <xs:complexType name="type-name">
    as the name attribute on the local complex type is prohibited thus the
    schema is not valid.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Apr 10, 2005
    #4
  5. Hi all,

    For those who wonder I posted the same question on the w3c schema list
    and everyone agreed this construct was forbidden by the spec (look up
    the thread in archives for all the normative quotations)

    So my problem is solved.

    Thanks to everyone involved here

    --
    Nicolas Mailhot
    Nicolas Mailhot, Apr 11, 2005
    #5
    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.
Similar Threads
  1. Moth
    Replies:
    2
    Views:
    420
  2. Wolfgang
    Replies:
    2
    Views:
    730
    Wolfgang
    Oct 7, 2003
  3. tsolbjor
    Replies:
    0
    Views:
    490
    tsolbjor
    Jul 19, 2004
  4. Peter Theill

    complexType in Xml Schema

    Peter Theill, Nov 25, 2004, in forum: XML
    Replies:
    2
    Views:
    463
    Peter Theill
    Nov 25, 2004
  5. Istvan
    Replies:
    1
    Views:
    781
    Istvan
    Aug 22, 2006
Loading...

Share This Page