The markup declarations contained or referenced by the document type declaration must be well formed

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 the 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)>
]>

      

I am getting this error:

Fatal error: Public ID: null System ID: file / home / p 14524 / plantdtd.dtd Line number: 4 Column number: 3 Message: Statements contained markup or sharpened with document type The declaration must be well formed.

Can anyone please explain who might be getting this error? or the correct DTD?

EDIT AND UPDATES: Ah! Thank you Daniel. Now the previous error is gone. My 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)>

<!ATTLIST plant id ID #REQUIRED>

      

I am getting this new error:

Line number: 18 Column number: 9 Message :. The content of an element of type "Plant" must correspond to "(name, climate, height, use, image)"

+3


source to share


1 answer


You need to remove DOCTYPE

from DTD. You must also have spaces after element names in 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 several errors when validating your XML.

First, you need to declare an attribute on the id

element plant

. I suggest <!ATTLIST plant id ID #REQUIRED>

.

Secondly, it is climate

absent in the second plant

. I'm not sure if this is an XML error or a DTD error. Declaring an element for plant

doesn't make a lot of sense, because it's 5 elements in that order one or more times. If you need help with this part, please describe what it should contain plant

and I can help you write the correct ad.

+1


source







All Articles