Search code examples
xmldtdxml-validation

XML DTD validation: character not allowed in declaration subset


Despite the presence of a root element and having inserted all the attribute in the ATTLIST of the DTD, I am incurring in several errors on the w3 validator:

Error Line 17, Column 9: character "g" not allowed in declaration subset gender CDATA #REQUIRED>

Error Line 21, Column 45: there is no attribute "gender" … <person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">

Error Line 21, Column 58: there is no attribute "email" … <person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">

Error Line 29, Column 22: document type does not allow element "lastdownload" here <lastdownload> PokemonGo </lastdownload>

Error Line 30, Column 19: document type does not allow element "lastlogin" here <lastlogin> 12.03.2016 </lastlogin>

This is my XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [
<!ELEMENT catalog (person+)>
<!ELEMENT person (firstname,lastname,telephone,city,address, preferences, newsletter, downloads)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT telephone (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT preferences (#PCDATA)>
<!ELEMENT newsletter (#PCDATA)>
<!ELEMENT lastdownload (#PCDATA)>
<!ELEMENT lastlogin (#PCDATA)>
<!ELEMENT downloads (#PCDATA)>
<!ATTLIST person 
        user CDATA #REQUIRED>
        gender CDATA #REQUIRED>
        email CDATA #REQUIRED>
]>
<catalog>
        <person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
        <firstname> X </firstname>
        <lastname> XXXX </lastname>
        <telephone> 06666666 </telephone>
        <city> ZZZZZ </city>
        <address> Azxxxxxh xxx </address>
        <preferences> Educational </preferences>
        <newsletter> Yes </newsletter>
        <lastdownload> PokemonGo </lastdownload>
        <lastlogin> 12.03.2016 </lastlogin>
        <downloads> 5 </downloads>
    </person>
</catalog>

Solution

  • There are severals errors to fix:

    1. Remove the extra > characters in the ATTLIST.
    2. add lastdownload and lastlogin to the content model of catalog.

    Here is your XML with all fixes applied:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE catalog [
    <!ELEMENT catalog (person+)>
    <!ELEMENT person (firstname,lastname,telephone,city,address, preferences, 
                      newsletter, lastdownload, lastlogin, downloads)>
    <!ELEMENT firstname (#PCDATA)>
    <!ELEMENT lastname (#PCDATA)>
    <!ELEMENT telephone (#PCDATA)>
    <!ELEMENT city (#PCDATA)>
    <!ELEMENT address (#PCDATA)>
    <!ELEMENT preferences (#PCDATA)>
    <!ELEMENT newsletter (#PCDATA)>
    <!ELEMENT lastdownload (#PCDATA)>
    <!ELEMENT lastlogin (#PCDATA)>
    <!ELEMENT downloads (#PCDATA)>
    <!ATTLIST person 
            user CDATA #REQUIRED
            gender CDATA #REQUIRED
            email CDATA #REQUIRED>
    ]>
    <catalog>
      <person user="WhozYourDaddy" gender="male" email="whozyourdaddy@gmail.com">
        <firstname> X </firstname>
        <lastname> XXXX </lastname>
        <telephone> 06666666 </telephone>
        <city> ZZZZZ </city>
        <address> Azxxxxxh xxx </address>
        <preferences> Educational </preferences>
        <newsletter> Yes </newsletter>
        <lastdownload> PokemonGo </lastdownload>
        <lastlogin> 12.03.2016 </lastlogin>
        <downloads> 5 </downloads>
      </person>
    </catalog>