creating recurrent tags in XML Schema

Ruthless (2)

Usenet Archive
Joined
Nov 29, 2003
Messages
3
Reaction score
0
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
 

C. M. Sperberg-McQueen

Usenet Archive
Joined
Jul 2, 2003
Messages
95
Reaction score
0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top