W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2008

Re: Recursive XSD with targetNamespace

From: Todd Moon <tmrfcm@gmail.com>
Date: Fri, 14 Nov 2008 16:13:32 -0500
Message-ID: <2dc6e4c80811141313v253f371do2c0f15ec120373a4@mail.gmail.com>
To: "Michael Kay" <mike@saxonica.com>
Cc: xmlschema-dev@w3.org
This worked, but it doesn't make a lot of intuitive sense to me. The
namespace specified in the targetNamespace is the namespace of the document
to be validated. The Item type is defined in the schema. Why should I have
to use the target namespace when referencing a type defined and used within
the schema?

Do all types defined in the schema automatically share the namespace
specified in targetSchema?

Thanks!

- Todd Moon

On Fri, Nov 14, 2008 at 4:01 PM, Michael Kay <mike@saxonica.com> wrote:

>  Whenever you refer to a component in a namespace, you need to use a
> qualified name. So it should be
>
> type="foo:Item"
>
> having declared
>
> xmlns:foo="http://foo"
>
> Michael Kay
> http://www.saxonica.com/
>
>  ------------------------------
> *From:* xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org]
> *On Behalf Of *Todd Moon
> *Sent:* 14 November 2008 20:24
> *To:* xmlschema-dev@w3.org
> *Subject:* Recursive XSD with targetNamespace
>
> Hello everyone.
>
> I have a recursively defined type called "Item" and the schema works fine
> at first. However, if I specify a targetNamespace in the XSD, Visual Studio
> gives me an error claiming that "Item" is not defined (when it's used within
> the definition of Item itself.)
>
> Here's a greatly simplified schema that still exposes the problem:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <xsd:schema
>    targetNamespace="http://foo"
>    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
>    <xsd:complexType name="Item">
>        <xsd:sequence>
>            <xsd:element name="SerialNumber" />
>            <xsd:sequence>
>                <xsd:element name="Item" type="Item" />
>            </xsd:sequence>
>        </xsd:sequence>
>    </xsd:complexType>
>
> </xsd:schema>
>
> If I remove the targetNamespace attribute this works fine. Why is this
> causing a problem?
>
> Thanks!
>
> - Todd Moon
>
>
Received on Friday, 14 November 2008 21:14:08 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:09 GMT