0

Hey guys i've got a XML DTD code that is external but when i try and validate it, i seem to get an error. The code i have is below:

<!DOCTYPE catalog [ 
    <!ELEMENT catalog (book)+>
    <!ELEMENT book (title, authors, year_published, ISBN, number_of_pages, price) >
    <!ELEMENT title (#PCDATA)>
    <!ELEMENT authors (author)>
    <!ELEMENT author (first_name, last_name, gender)>
        <!ELEMENT first_name (#PCDATA)>
        <!ELEMENT last_name (#PCDATA)>
        <!ELEMENT gender (#PCDATA)>
    <!ELEMENT year_pusblished (#PCDATA)>
    <!ELEMENT ISBN (#PCDATA)>
    <!ELEMENT number_of_pages (#PCDATA)>
    <!ELEMENT price (discount)>
        <!ATTLIST price discount (yes|no) "no">]>

I know everything is correct but when i validate it the error message comes up:

"Markup declarations contained in or pointed to by document type declaration must be well-formed. Line 3 Column 4"

i've checked everything but i can't seem to get it working. Are you guys able to help?

user1618490
  • 771
  • 3
  • 8
  • 13

1 Answers1

0

If you write into file .xml you have no error generated, but if you have a .dtd file you must clear the element! Correct file test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog [ 
<!ELEMENT catalog (book)+>
<!ELEMENT book (title, authors, year_published, ISBN, number_of_pages, price) >
<!ELEMENT title (#PCDATA)>
<!ELEMENT authors (author)>
<!ELEMENT author (first_name, last_name, gender)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT year_pusblished (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT number_of_pages (#PCDATA)>
<!ELEMENT price (discount)>
<!ATTLIST price discount (yes|no) "no">]>
<catalog>
    <book>
        <title></title>
        <authors>
            <author>
                <first_name></first_name>
                <last_name></last_name>
                <gender></gender>
            </author>
        </authors>
        <year_published></year_published>
        <ISBN></ISBN>
        <number_of_pages></number_of_pages>
        <price>
            <discount></discount>
        </price>
    </book>
</catalog>

Correct file test.dtd (linked to xml file with declaration into same test.xml ):

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT catalog (book)+>
<!ELEMENT book (title, authors, year_published, ISBN, number_of_pages, price) >
<!ELEMENT title (#PCDATA)>
<!ELEMENT authors (author)>
<!ELEMENT author (first_name, last_name, gender)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT year_pusblished (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT number_of_pages (#PCDATA)>
<!ELEMENT price (discount)>
<!ATTLIST price discount (yes|no) "no">
steguozzo
  • 55
  • 9