creating recurrent tags in XML Schema

Discussion in 'XML' started by, Nov 29, 2003.

  1. Guest


    i've got a question

    can i in XML Schema define tag that works as lists knows from e.g. C,C++ -
    recurrent tags?

    i'm talking about e.g. genealogical tree every level of this tree is the

    1) Grandparents // parents for the level 2
    2) parenst // parents for the level 3
    3) children // parents for the next level

    and so on...

    can you help me with simple recuretion example?

    thanks in advance
    greetings R

    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (
    Version: 6.0.542 / Virus Database: 336 - Release Date: 03-11-18
    , Nov 29, 2003
    1. Advertisements

  2. "" <> writes:

    > can i in XML Schema define tag that works as lists knows from e.g. C,C++ -
    > recurrent tags?

    You can certainly define recursive elements types in XML

    > can you help me with simple recuretion example?

    Sure. Here is a simple schema for documents with titles,
    paragraphs, and sections (tagged 'doc', 'title', 'p', and
    'div'), in which sections are recursive (i.e. 'div' elements
    can contain 'div' elements).

    targetNamespace="" >

    <xsd:element name="doc" type="T-div"/>
    <xsd:element name="div" type="T-div"/>
    <xsd:element name="p"/>
    <xsd:element name="title"/>

    <xsd:complexType name="T-div">
    <xsd:element ref="title"/>
    <xsd:element ref="p" minOccurs="0" maxOccurs="unbounded"/>
    <xsd:element ref="div" minOccurs="0" maxOccurs="unbounded"/>


    Here is a document using that schema:

    <my:doc xmlns:my=""
    =" ruthless.xsd">
    <my:title>Simple document showing recursion</my:title>
    <my:p>This document illustrates the 'simple recursive example' schema.</my:p>
    <my:p>The same structure is used for the 'doc' and the 'div' elements,
    and the definition of the 'div' element is recursive: 'div' elements
    can nest within 'div' elements. </my:p>
    <my:title>The 'document' element</my:title>
    <my:p>The document contains a title, a series of paragraphs,
    and a series of 'div' elements.</my:p>
    <my:title>The 'div' element</my:title>
    <my:p>Like the 'doc' element, any 'div' element can
    contain a title (required),
    a series of zero or more paragraphs,
    and a series of zero or more 'div' elements.</my:p>
    <my:title>The parallel between doc and div</my:title>
    <my:p>The identity of structure between 'doc' and 'div' elements
    is captured in the schema by using the same complex type
    (T-div) for both the 'doc' element and the 'div' element.</my:p>
    <my:title>The <my:title>recursion</my:title></my:title>
    <my:p>The ability of 'div' elements to contain other 'div' elements
    is expressed in the schema by the simple expedient of naming
    the 'div' element as a possible child of the 'div' element.</my:p>

    Note that because they are implicitly declared as having the ur-type
    (type xsd:anyType), the 'title' and 'p' elements can also self-nest,
    as illustrated in the last 'my:title' element.

    I hope this helps.

    -C. M. Sperberg-McQueen
    World Wide Web Consortium
    C. M. Sperberg-McQueen, Nov 30, 2003
    1. Advertisements

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.

Share This Page