Search code examples
xmldtd

The content of element type "plant" must match (name,climate,height,usage,image)


I am writing a DTD for the below xml code.However the output is

The content of element type "plant" must match (name,climate,height,usage,image)

Here is my xml code

<?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>

This is my DTD.

<?xml encoding="UTF-8"?>
<!ELEMENT catalog (title,plant+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT plant (name,climate,height,usage,image)>
<!ATTLIST plant id CDATA  #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT climate (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT usage (#PCDATA)>
<!ELEMENT image (#PCDATA)>

Please tell me whats wrong with the above DTD.


Solution

  • Assuming that the instance document is "right" and the DTD is "wrong", then you need to change the DTD to allow climate to be omitted (write climate?) and to allow usage to be repeated (write usage+). That will make these two example plant elements valid, but of course to design the DTD you need to consider all possible valid plant elements, not just these two.