The markup declarations contained or pointed to by the document type declaration must be well-formed
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.
isekaid_maou
Updated on June 06, 2022Comments
-
isekaid_maou almost 2 years
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)".
-
isekaid_maou almost 7 yearsCan you please check the latest update of my question and answer back.
-
Daniel Haley almost 7 years@RaviRishie - That error is what I was talking about in the last paragraph of my answer. Your second
plant
doesn't match(name,climate,height,usage,image)
because it doesn't have aclimate
element. Is that element supposed to be optional? I also see it now has twousage
elements. Maybe you'd rather use<!ELEMENT plant (name,climate?,height?,usage*,image*)>
or something? -
isekaid_maou almost 7 yearsThanks dude! Its working fine by mentioning the occurences here
-
Daniel Haley almost 7 years@RaviRishie - Awesome! Glad I could help!
-
isekaid_maou almost 7 yearsPlease check this one too stackoverflow.com/questions/44344663/…