recursive xml schema - going in the right direction?

U

Ultrus

Hello XML gurus,
After much reading, I made my first XML Schema! May I trouble you all
for your thoughts? Perhaps there is a better way to go about it, or I
did something totally wrong without knowing.

My project goal is to make a randomly generated story generator using
recursive xml. There will be random elements within random elements,
within random elements, etc.,.


Here is sample xml:

<randomstory>
<settings />
<story>
Once upon a time...
<random>
<i>A man was born. No one knew what became of him.</i>
<i>
A man was born.
<random>
<i>He grew up, lived long, prospered, then died.</i>
<i>He joined the Navy, fell off the boat, then died.</i>
</random>
</i>
</random>
The end.
</story>
</randomstory>


Here is sample output:

Once upon a time... A man was born. He joined the Navy, fell off the
boat, then died. The end.


Here is the schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">

<xs:element name="randomstory">
<xs:complexType>
<xs:all>
<xs:element name="settings" minOccurs="0" maxOccurs="1" />
<xs:element name="story" minOccurs="1" maxOccurs="1">
<xs:complexType mixed="true">
<xs:all>
<xs:element name="random" type="randomType"
minOccurs="0" maxOccurs="unbounded"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>

<xs:complexType name="randomType">
<xs:sequence>
<xs:element name="i" type="iType" minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="iType" mixed="true">
<xs:all>
<xs:element name="random" type="randomType" minOccurs="0"
maxOccurs="unbounded"/>
</xs:all>
</xs:complexType>

Pardon any odd line breaks. Any thoughts? Much appreciated! :)
 

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
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top