I have this xml document:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog SYSTEM "plantdtd.dtd">
<catalog>
<title>Flowers of the week</title>
<plant id="A1">
<name>Aloe vera</name>
<climate>tropical</climate>
<height>60-100cm</height>
<usage>medicinal</usage>
<image>aloevera.jpg</image>
</plant>
<plant id="A2">
<name>Orchidaceae</name>
<height>8-12in</height>
<usage>medicinal</usage>
<usage>decoration</usage>
<image>Orchidaceae.jpg</image>
</plant>
</catalog>
I wrote a DTD like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog SYSTEM "file:/home/p10398/plantdtd.dtd"
[
<!ELEMENT catalog(title,plant+)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT plant(name,climate,height,usage,image)+>
<!ELEMENT name(#PCDATA)>
<!ELEMENT climate(#PCDATA)>
<!ELEMENT height(#PCDATA)>
<!ELEMENT usage(#PCDATA)>
<!ELEMENT image(#PCDATA)>
]>
Iam getting this error:
Fatal error: Public ID: null System ID: file:/home/p14524/plantdtd.dtd Line number: 4 Column number: 3 Message: The markup declarations contained or pointed to by the document type declaration must be well-formed.
Can someone explain whay Iam getting this error? or the correct DTD?
EDITS and UPDATES: Ah! Thanks Daniel. Now the previous error is gone. My new DTD is
<!ELEMENT catalog (title,plant+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT plant (name,climate,height,usage,image)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT climate (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT usage (#PCDATA)>
<!ELEMENT image (#PCDATA)>
<!ATTLIST plant id ID #REQUIRED>
Iam getting this new error:
Line number: 18 Column number: 9 Message: The content of element type "plant" must match "(name,climate,height,usage,image)".
You need to remove the DOCTYPE
from the DTD. You should also have spaces after the element names in the declarations.
New DTD
<!ELEMENT catalog (title,plant+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT plant (name,climate,height,usage,image)+>
<!ELEMENT name (#PCDATA)>
<!ELEMENT climate (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT usage (#PCDATA)>
<!ELEMENT image (#PCDATA)>
Now that the DTD is valid, you will see a few errors when validating your XML.
The first is that you need to declare the id
attribute of the plant
element. I'd suggest <!ATTLIST plant id ID #REQUIRED>
.
The second is that climate
is missing from the second plant
. I'm not sure if that's an XML error or a DTD error. The element declaration for plant
doesn't make a whole lot of sense though because it's those 5 elements in that order one or more times. If you need help with that piece, describe what plant
should contain and I can help you write the right declaration.