Element + complextype name in xml schema

  • Thread starter Nicolas Mailhot
  • Start date
N

Nicolas Mailhot

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,
 
M

Martin Honnen

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" />
 
N

Nicolas Mailhot

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
 
M

Martin Honnen

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.
 
N

Nicolas Mailhot

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
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top