"Christine McGavran" <cm*******@perpetualent.com> writes:
Today we upgraded to Visual Studio .net 2003. One of the
changes seems to be that schema files are compiled instead
of interpreted directly. The compiler gives the following
error on compile: "DataSet doesn't allow the circular
reference in the ComplexType named 'Window'". So no more
fancy editing. :(
Is that the entirety of the error message?
This isn't a Microsoft-specific problem, I get a similar
error if I try to use an application I downloaded via w3.org
to validate xml using my schema.
More details, please? Do you mean XSV? If so, what exactly is the
error code XSV is giving you? I don't get any schema error from XSV
on the sample schema you provided (although I do get errors on any
document I provide, for reasons which will become clear below).
My script allows you to create windows with child windows,
which can also have children. A pretty standard windowing system,
I think. But it doesn't seem legal xml to make a window element a
child of a window element.
Ouch! No! Don't think that!
There is nothing in XML or in XML Schema that makes such
recursion illegal. (And to be fair, note that the error message
you quote from Visual Studio doesn't actually say it's illegal
XML, or a schema error. It says there is something there that
Visual Studio doesn't support.)
I'm not really familiar with all the logic and theory behind xml,
I just thought it was a convenient way to script our UI. I would
like to understand why these "circular references" are not allowed
in the schema, and what alternatives a proper xml guru might suggest
for my situation.
Below is a simple schema that has this problem
I'll take you at your word, though I suspect you did not
paste this in direct from a schema document that got the
same error message you give above. (I suspect it because
the xmlns attribute is missing its required quotation marks,
and you should have gotten a well-formedness error long
before anyone started worrying about circularity.)
<schema targetNamespace="test.xsd"
elementFormDefault="qualified"
xmlns=http://www.w3.org/2001/XMLSchema
er, "http://www.w3.org/2001/XMLSchema"
xmlns:ui="test.xsd">
<element name="test">
<complexType>
<sequence>
<element name="window" type="ui:Window" />
</sequence>
</complexType>
</element>
<complexType name="Window">
<sequence>
<element name="children">
<complexType>
<sequence>
<element name="childWindow"
type="ui:Window" />
</sequence>
</complexType>
</element>
<element name="testString" type="string" />
</sequence>
</complexType>
</schema>
If Visual Studio is complaining about the same problem
I see with this schema, I have to say I'm moderately
impressed with its acuity.
Both XSV and Xerces J believe, as I do, that the schema
document you give is valid, once the xmlns attribute gets
its quotation marks. The only problem with it is that
there are no finite documents which conform to it.
The problem is not the recursion per se, it's the fact
that there is no bottom to it, just as in the following
instructions there is no way to reach step 5.
0 Start. Go to step 1.
1 You have a top-level element named 'test', which has
a required child named 'window'. Go to step 2.
2 The 'window' element, being of type ui:Window, has
required children named 'children' and 'testString'.
Go to step 3.
3 The 'children' element has exactly one required child
named 'childWindow'. Go to step 4.
4 The 'childWindow' element, being of type ui:Window, has
required children named 'children' and 'testString'.
Go to step 3.
5 Done.
If I change the schema so that the childWindow element is
optional, then I can create a finite document which conforms
to the schema. In practice, I suspect you also want to
specify that a window can have more than one childWindow
among its children. One way to do this is to change the
declaration for 'childWindow' thus:
<element name="childWindow"
minOccurs="0"
maxOccurs="unbounded"
type="ui:Window" />
There are other ways, of course.
Is this the problem with your real schema, or is the
absence of the minOccurs and maxOccurs an artifact of
the way you cut down the problem for presentation in
your post?
You asked what alternatives others might suggest. My
first suggestion is to correct the occurrence information.
My second would be to change the name of the child
window to 'window', to make the recursion even more
obvious, unless there is a strong reason to distinguish
top-level windows from others (in which case, I'd
probably use the names 'topWindow' and 'window'
rather than 'window' and 'childWindow' -- but naming
is a matter of taste, and you should suit yourself and
your collaborators, not me).
I hope this helps,
-C. M. Sperberg-McQueen
World Wide Web Consortium