473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Learning XML.

Hi everyone,

I'm learning XML and have read a couple of site on the topic, but I'm
wondering how to implement something like this in a DTD.
<root>
<header>
<nameSome data </name>
<date month="12", day="01", year="2005" />
<author name="Bob" />
<note Bob wrote this. </note>
</header>
</root>

However, the <nametag is required, but all the others are optional.
Also, the name tag must appear first but it does not matter what order
the other fields appear in or if they even appear at all. So another
example of the document could be...

<root>
<header>
<nameAnother Example </name>
<author name="Sue" />
</header>
</root>

or...

<root>
<header>
<nameA different example. </name>
<author name="Joe" />
<note Quick example for you to look at. </note>
<date month="1", day="1", year="2004" />
</header>
</root>

I've come up with this much so far.

<!ELEMENT root (header)>
<!ELEMENT header (name, (author | note | date)?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT author EMPTY>
<!ELEMENT note (#PCDATA)>
<!ELEMENT date EMPTY>

<!ATTLIST author name CDATA #REQUIRED>
<!ATTLIST date month CDATA #REQUIRED>
<!ATTLIST date day CDATA #REQUIRED>
<!ATTLIST date year CDATA #REQUIRED>

I would also like to include that the author, note, and date element
can be used once or not at all. And if you use one of those elements
then you must use the the attributes listed.

I thank you all in advance for any help. Also if you could suggest
some tool that I can use in Linux to help me with XML and validation.

Thanks!

Sep 11 '06 #1
2 1186
ju******@gmail.com wrote:
I would also like to include that the author, note, and date element
can be used once or not at all.
In DTDs, that kind of constraint -- any order but only one instance --
is painful to express. You wind up having to enumerate all the possible
sequences. Not difficult, but verbose and a pain to maintain.

Suggestions:

1) Abandon DTDs and move to XML Schemas, which are a more powerful
constraint language.

or

2) Insist that the contents appear in a specified order. There really
isn't any strong advantage to allowing the any-order flexibility unless
the order is going to be meaningful -- which, in this case, it clearly
isn't. Programs can easily generate stuff in the right order, and so can
humans once they stop grumbling that you should have let them be lazy.
If you want to be kind to them, provide a tool (eg an XSLT stylesheet)
which will help get the documents into valid form.
Note that there are likely to be be some constraints in a serious XML
application that can't be expressed in either DTD or schema. These
formalisms are very useful and as documentation for what your program
expects, and as an initial sanity-check layer ... I like to think of it
as "higher level syntax" ... but the program itself is often going to
have to do some additional checking to enforce specific semantic
constraints.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Sep 11 '06 #2
ju******@gmail.com wrote:
Hi everyone,

I'm learning XML and have read a couple of site on the topic, but I'm
wondering how to implement something like this in a DTD.
<root>
<header>
<nameSome data </name>
<date month="12", day="01", year="2005" />
<author name="Bob" />
<note Bob wrote this. </note>
</header>
</root>

However, the <nametag is required, but all the others are optional.
Also, the name tag must appear first but it does not matter what order
the other fields appear in or if they even appear at all.
If the order is not important, then fix it:

<!ELEMENT root (header)>
<!ELEMENT header (name,author?,note?,date?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT author EMPTY>
<!ELEMENT note (#PCDATA)>
<!ELEMENT date EMPTY>

<!ATTLIST author name CDATA #REQUIRED>
<!ATTLIST date month CDATA #REQUIRED
day CDATA #REQUIRED
year CDATA #REQUIRED>

Or perhaps simpler, <!ATTLIST date YYYY-MM-DD CDATA #REQUIRED>

The "any order but once each" facility in SGML was removed from XML
to make it simpler. Joe posted some good suggestions about Schemas.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Sep 11 '06 #3

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

Similar topics

5
by: Ron Stephens | last post by:
The newly rechristened Python Learning Foundation is a web site dedicated to the assistance of people learning the Python programming language. Features include: 1. Daily lists of new and recent...
29
by: Jhon smith | last post by:
Hi,all,I was just wondering if I am likly to have any problems trying to learn C from older books,I have some from the late 80`s,mid/late 90`s. I am using Dev-C++ on the pc windows platform,But I...
4
by: Christian Blackburn | last post by:
Hi Gang, I saw this for sale online: Microsoft Visual Basic.NET Deluxe Learning Edition Version 2003. I'm wondering is the CD that's bundled with the learning edition just a digitized version of...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
7
by: Max | last post by:
On monday I start a semester course in Python (the alternative was Java). I was looking through the course outline and noticed the following: 1) UserDict is used. This is deprecated, right? 2)...
36
by: utab | last post by:
Dear, I have experince in C( numerical projects, like engineering problems, scientific applications) I have the basic notion of C++ also, I have read Accelerated C++ until Chapter 7, however it...
2
by: bokiteam | last post by:
Hi All, Here is my idea to save learning time - Personal learning book. What we really need is somebody really familiar our learning experience, and then takes the example to teach us. Save...
78
by: arnuld | last post by:
hai all, i am standing on a "crossroad to C++". I am here in front of you as i have a problem. i will be brief. Please do not think: "arnuld is sick", i am really struggling & doing hard-work to...
0
by: LK~ICT | last post by:
Sri Lanka rural e-learning project seeks corporate support Dec 04, 2007 (LBO) - A Sri Lankan e-learning initiative for rural students is seeking corporate sector support to expand and cover 400...
16
by: John Salerno | last post by:
Just something that crosses my mind every time I delve into "Learning Python" each night. Does anyone see any value in learning Python when you don't need to for school, work, or any other reason?...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.