cant get DTD to work

D

Dummy

Hey there, I'm trying to get my DTD to work with some content, just
wondering if someone could take a look at it for me and see where im
going wrong. Thanks,

<?xml version="1.0"?>
<!DOCTYPE holiday [
<!ELEMENT holiday (entry_date+)>
<!ELEMENT entry_date (activities?, purchases, weather, food?,
photos*)>
<!ELEMENT activities (#PCDATA)>
<!ELEMENT purchases (#PCDATA)>
<!ATTLIST weather (sunny | rainy | cloudy | snowy) "sunny">
<!ELEMENT photos (#PCDATA)>
<!ELEMENT food (#PCDATA)>
]>

<holiday>
<entry_date>
<activities>I went to the beech. It was super fun.</activities>
<purchases>I bought some new clothes at a stall.</purchases>
<weather>sunny</weather>
<food>I had some fish. Yummmmmmy.</food>
<photos>http://www.floridaflorida.org/Beach1.jpg</photos>
</entry_date>
<entry_date>
<activities>Skiing in the alps with Tilly and Minny.</activities>
<purchases>New ski goggles.</purchases>
<weather>snowy</weather>
<food>We ate crips and drank pop.</food>
<photos>http://www.lasource.f9.co.uk/images/Michael skiing 1.jpg</
photos>
</entry_date>
</holiday>
 
M

Martin Honnen

Dummy said:
<!ATTLIST weather (sunny | rainy | cloudy | snowy) "sunny">

<weather>sunny</weather>

I think you want
<!ATTLIST weather
type (sunny | rainy | cloudy | snowy) "sunny")>

<wheather type="sunny"/>

Or give the entry-date element an attribute named wheather-type.
 
M

Martin Honnen

You might also want to switch the W3C XSD schemas instead of DTDs as the
schema language allows you to enumerate the possible values of
attributes as well as of elements
<xs:element name="wheather">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="sunny"/>
<xs:enumeration value="rainy"/>
<xs:enumeration value="cloudy"/>
<xs:enumeration value="snowy"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
 
C

charlieo0

Your problem is that you never declared the "weather" element.

You have <!ATTLIST weather> but nowhere do you have <!ELEMENT weather>
 
R

Richard Tobin

Dummy said:
<!ATTLIST weather (sunny | rainy | cloudy | snowy) "sunny"> ....
<weather>snowy</weather>

ATTLIST is for declaring attributes, not elements. DTDs don't have
any way of listing the possible values for the text content of an
element.

-- Richard
 

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top