circular references in schemas

Discussion in 'XML' started by Christine McGavran, Jan 29, 2004.

  1. I have created an xml format for describing a custom user interface. My
    application successfully parses and displays the UI described in xml files
    created in that format.

    Before today we were using Visual Studio .net 2002. I created a schema file
    to describe my xml so that I could use the fancy xml editing capabilities in
    the Visual Studio enviroment. With this schema referenced, I could
    auto-complete while scripting xml for my user interface while editing in
    DevStudio. A pretty neat feature, even though it wasn't really necessary.

    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. :(

    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.

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

    <schema targetNamespace="test.xsd" elementFormDefault="qualified"
    xmlns=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>
    Christine McGavran, Jan 29, 2004
    #1
    1. Advertising

  2. "Christine McGavran" <> 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
    C. M. Sperberg-McQueen, Jan 29, 2004
    #2
    1. Advertising

  3. > Is that the entirety of the error message?

    yes

    > Do you mean XSV?


    I'm not really sure what Microsoft uses, but I don't think it's XSV. The
    tool is called "XML Data Proxy Generator."

    > I don't get any schema error from XSV
    > on the sample schema you provided
    > There is nothing in XML or in XML Schema that makes such
    > recursion illegal.

    Then maybe it's a Microsoft issue after all.. I've also posted to the
    Microsoft group.

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


    You know I did paste it directly, but the document I pasted from has the
    quotation marks. Beats me why they got left out... probably some Outlook
    thing. :p

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

    Doing this doesn't change my results at all.

    > 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?


    I knew about the minOccurs/maxOccurs thing, but Microsoft seemed to ignore
    them, at least in the old version of DevStudio, so I had left them out of my
    test.

    > My second would be to change the name of the child
    > window to 'window', to make the recursion even more
    > obvious


    My actual schema (not the test) does this, actually. I was just trying to be
    clear for the test.

    > I hope this helps,


    Wish it did. I do thank you for letting me know I'm not trying to do
    something entirely weird.
    Christine McGavran, Jan 29, 2004
    #3
  4. Just to follow-up, I got the response below from the Microsoft group.

    I did finally manage to get the smart editor to work on my test schema
    without the compile step, so I guess the compile step isn't needed after all
    for the editing feature (which is all I really cared about). My real schema
    doesn't work yet, so I guess I just rebuild it step-by-step until I figure
    out what it doesn't like, when I get some time.

    --

    that is a drawback of the Data View in vs.net, it would never lend
    itself well to this type of implementation.

    "The Visual Studio .NET XML Designer applies the Microsoft ADO.NET
    schema inference rules to determine the schema information for the
    source XML when it tries to generate Data view. The ADO.NET schema
    inference rules in the RTM release of the Microsoft .NET Framework do
    not permit a single table to be a child table in more than one
    DataRelation. "
    Christine McGavran, Jan 30, 2004
    #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.
Similar Threads
  1. Dan C Douglas

    Circular references are not supported

    Dan C Douglas, Aug 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,402
    Steve C. Orr, MCSD
    Aug 13, 2003
  2. Bill Jones

    Re: Circular References

    Bill Jones, Apr 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    422
    =?Utf-8?B?RGF2ZQ==?=
    Apr 8, 2004
  3. =?Utf-8?B?S2VpdGggRi4=?=

    Circular References in Visual Studio

    =?Utf-8?B?S2VpdGggRi4=?=, Aug 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    6,246
    Cowboy \(Gregory A. Beamer\) [MVP]
    Aug 6, 2004
  4. BBuff
    Replies:
    0
    Views:
    2,449
    BBuff
    Sep 26, 2005
  5. Kiuhnm
    Replies:
    16
    Views:
    728
    Jonathan Mcdougall
    Jan 3, 2005
Loading...

Share This Page