creating recurrent tags in XML Schema

Discussion in 'XML' started by ruthless@poczta.onet.pl, Nov 29, 2003.

  1. Guest

    hello.

    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
    same

    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 (http://www.grisoft.com).
    Version: 6.0.542 / Virus Database: 336 - Release Date: 03-11-18
    , Nov 29, 2003
    #1
    1. Advertising

  2. "" <ruthless@CUT_THIS.poczta.onet.pl> 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
    Schema.

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

    <xsd:schema
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://example.com/simple-recursive-example"
    targetNamespace="http://example.com/simple-recursive-example" >

    <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:sequence>
    <xsd:element ref="title"/>
    <xsd:element ref="p" minOccurs="0" maxOccurs="unbounded"/>
    <xsd:element ref="div" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    </xsd:complexType>

    </xsd:schema>

    Here is a document using that schema:

    <my:doc xmlns:my="http://example.com/simple-recursive-example"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
    ="http://example.com/simple-recursive-example 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:div>
    <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:div>
    <my:div>
    <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:div>
    <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:div>
    <my:div>
    <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>
    </my:div>
    </my:div>
    </my:doc>

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

Share This Page