473,699 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

my first xml schema - I think it's good. Is it really?

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.c om"
xmlns="http://www.w3schools.c om"
elementFormDefa ult="qualified" >

<xs:element name="randomsto ry">
<xs:complexType >
<xs:all>
<xs:element name="settings" minOccurs="0" maxOccurs="1" />
<xs:element name="show" minOccurs="1" maxOccurs="1">
<xs:complexTy pe mixed="true">
<xs:all>
<xs:element name="random" type="randomTyp e"
minOccurs="0" maxOccurs="unbo unded"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>

<xs:complexTy pe name="randomTyp e">
<xs:sequence>
<xs:element name="i" type="iType" minOccurs="1"
maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>

<xs:complexTy pe name="iType" mixed="true">
<xs:all>
<xs:element name="random" type="randomTyp e" minOccurs="0"
maxOccurs="unbo unded"/>
</xs:all>
</xs:complexType>

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

Jul 19 '07 #1
3 1896
Peter,
That was very helpful! I can see how my initial draft could be
confusing. Your DTD was also very much smaller than the XML Schema.

While chatting, research, and posting, people are telling me that XML
Schema may replace DTD. What are your thoughts on this? To me this
doesn't matter right now as my xml interpreter will take DTD or XML
Schema for validation purposes. DTD does seam simpler in this case.

Jul 19 '07 #2
On 19 Jul, 15:39, Ultrus <ownthe...@gmai l.comwrote:
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.c om"
xmlns="http://www.w3schools.c om"
elementFormDefa ult="qualified" >

<xs:element name="randomsto ry">
<xs:complexType >
<xs:all>
<xs:element name="settings" minOccurs="0" maxOccurs="1" />
<xs:element name="show" minOccurs="1" maxOccurs="1">
<xs:complexTy pe mixed="true">
<xs:all>
<xs:element name="random" type="randomTyp e"
minOccurs="0" maxOccurs="unbo unded"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>

<xs:complexTy pe name="randomTyp e">
<xs:sequence>
<xs:element name="i" type="iType" minOccurs="1"
maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>

<xs:complexTy pe name="iType" mixed="true">
<xs:all>
<xs:element name="random" type="randomTyp e" minOccurs="0"
maxOccurs="unbo unded"/>
</xs:all>
</xs:complexType>

Pardon any odd line breaks. Any thoughts? Much appreciated! :)
Just a quick note on your schema...

An element within an xs:all can not have a maxOccurs greater than 1.

I think for what you want, you could change the xs:all to an
xs:choice.

HTH,

Pete.
--
=============== =============== ===============
Pete Cordell
Codalogic Ltd
for XML Schema to C++ data binding visit
http://www.codalogic.com/lmx/
=============== =============== ===============

Jul 20 '07 #3
Ultrus wrote:
don't see RelaxNG listed on the W3C's website. Is RelaxNG a dead end
in some way like DTDs are with namespaces?
RelaxNG is not part of the W3C's standard recommendations suite; it's a
competing tool. That isn't _necessarily_ a reason to avoid it; after
all, the SAX APIs didn't originate in the W3C either... but this is part
of the reason Relax is not more widely supported.

If you're concerned with portability of your data, stick with XML Schema
and/or DTD.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Jul 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2485
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. I've made a small list of some good and bad points of both. These points don't really go into the grammar aspects of these languages, but are more about secondary aspects. The grammar aspects are different, but both are suitable for validating...
10
43210
by: wackyphill | last post by:
I know in SQL Server the terms Database and Catalog are used interchangably. But a table is also assigned a schema. As seen in the INFORMATION_SCHEMA.Tables View. I don't get what this schema qualifier is all about. Like if a table has a schema of dbo. Can someone explain the relationship the schema has and what it is? Thanks.
2
1355
by: Cowboy (Gregory A. Beamer) - MVP | last post by:
We have an application right now that determines if an XML document sent in conforms to schema. What we have now been asked to do is add functionality that creates an exception report for all records that do not conform to our schema (XSD). One of the team members has built some functionality that loops through the records, node by node, and determines which nodes do not conform, but it is taking way too long to develop. Does anyone know...
10
1959
by: Al Christoph | last post by:
Please forgive me if this is the wrong place to post this. The last place I posted got me a fairly rude response. I guess vb.db people just don't want to think about XML as database. At any rate, here is what I posted: I have downloaded the final production version of VS 2005 pro after testing with Team version. I wonder if I've been screwed or if it's just too early on a Sunday morning. It seems to me that it was relatively trivial to...
12
5307
by: Whoever | last post by:
Hi, I'm trying to return an XmlDocument or XmlNode converted from a typed dataset. public XmlNode whatever() { MyTypedDataSet ds = new MyTypedDataSet(); return new XmlDataDocument(ds); }
16
6006
by: Brad Wood | last post by:
I'm using a 2.0 XmlReaderSettings object with setting.ValidationType set to ValdationType.Schema to validate a document against a schema. Following is a schema fragment (names altered): <xsd:element name="Stuff"> <xsd:complexType> <xsd:sequence> <xsd:element ref="RequiredSimpleThing1"/> <xsd:element ref="RequiredSimpleThing2"/> <xsd:element name="OptionalSimpleThing1" type="OptionalType"
9
3009
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13> <binaryobject3></binaryobject3>
3
5631
by: Eric Lilja | last post by:
Hello again, I'm having a new problem converting a dtd to an xml schema. This once is a little bit more complicated than in my previous question. The following file validates correctly: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE books > <books> <book title="Winter's Heart" isbn="123456789"> <author name="Robert Jordan"/>
3
9924
by: Eric Lilja | last post by:
Sorry for asking so many questions, but I've just started and need to get some things working so I can do the task that is before me. Consider this (validating) schema: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="myns" xmlns="myns" elementFormDefault="qualified"> <xs:element name="books"> <xs:complexType> <xs:sequence>
0
8617
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.