Reputation: 97
I'm getting markup declaration error at the atlist
declaration line in the following XML file:
<?xml encoding="UTF-8"?>
<!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)>
<!ATLIST plant id CDATA #REQUIRED>
<?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>
What is wrong with my XML document?
Upvotes: 0
Views: 1615
Reputation: 1
This error is caused by the DTD file not being valid. You have created a DTD-file containing:
<!DOCTYPE catalog [
…
]>
Simply remove the first and last line delcaring the DTD data, since those are only to be used when having the DTD within your XML file. And there should be ? in climate since in plant A2 it is not present.
`
<?xml version="1.0" encoding="UTF-8"?>
<!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 CDATA #REQUIRED>
`
Upvotes: 0
Reputation: 111706
Your XML document has both well-formedness and validity problems...
Problems preventing your XML document from being well-formed, including:
Problem preventing your XML document from being valid:
A2
plant
has to have at least one climate
child element.The following XML is corrected to be well-formed and valid:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [
<!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 CDATA #REQUIRED>
]>
<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>
<climate/>
<height>8-12in</height>
<usage>medicinal</usage>
<usage>decoration</usage>
<image>Orchidaceae.jpg</image>
</plant>
</catalog>
Upvotes: 1