Search code examples
xmlvalidationdtd

Why doesn't the XML validate to the DTD


DTD:

<?xml version="1.0" encoding="UTF-8"?>

<!ELEMENT language (definition, tu, tuv, seg) >
<!ELEMENT definition ANY >
<!ELEMENT tu ANY >
<!ELEMENT tuv ANY >
<!ELEMENT seg (#PCDATA) >
<!ATTLIST tu id CDATA #REQUIRED >
<!ATTLIST tuv lang CDATA #REQUIRED >

XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">

<definition> # This is the line that seems to be the problem
    <tu id="webpage-title-text">
        <tuv lang="en">
            <seg>Demo CMS</seg>
        </tuv>
    </tu>
</definition>

The error message I get is:

Document root element "definition", must match DOCTYPE root "language". [4]

My Questions:

  1. What is the reason so that the XML is not considered valid against the current DTD?
  2. What I have missed in the DTD?
  3. Could anyone recommend a good place to take as a resource of learning how to use DTDs, Schemas and etc.

Solution

  • Change

    <!DOCTYPE language SYSTEM "language.dtd">
    

    to

    <!DOCTYPE definition SYSTEM "language.dtd">