• 0

Issues Validating XML with DTD


Question

Hey guys.  So I've been taking an XML class but I am having trouble getting this file to validate correctly.  Keep getting that it is not well-formed.  Not sure where I am going wrong and can't find a solid answer, not to mention the teacher doesn't seem to know much about what she is teaching.

This is the error I get from xmlvalidation.com:

 

 

Errors in file photos.dtd: 

errorjump.png 13: 3 The markup declarations contained or pointed to by the document type declaration must be well-formed.

 

And when I use Notepad++ XML Tools validation I get:

XML Parsing error at line 31:

Start tag expected, '<' not found

 

Here is the XML:

 

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!--
   New Perspectives on XML
   Tutorial 2
   Case Problem 1

   Catalog of photos from the Our Lady of Bergen Historical Society
   Author: <removed>
   Date:   1/28/2016

   Filename:         photos.xml
   Supporting file:  photos.dtd
-->
<!DOCTYPE catalog SYSTEM "photos.dtd">
 
<catalog type="photos">

   <photo cid="c1748" donatedBy="John Borelli">
      <name metadata="tunis cooper property museum">Tunis R. Cooper property</name>
      <description>
      <![CDATA[ 
         This photo was taken by John Borelli's great-grandfather. It is believed to have been taken around 1830.
         David Demarest originally purchased the site of the chair factory in 1663. This site was under the ownership 
         of the Demarest family until 1758.  The property is listed in the National and New Jersey Registers of Historic Places.
      ]]>
      </description>
      <date>1830 circa</date>
      <images>
         <img src="1748a.jpg" />
         <img src="1748b.jpg" />
      </images>
   </photo>

   <photo cid="c1749" donatedBy="John Borelli">
      <name metadata="tunis cooper property museum">Tunis R. Cooper property</name>
      <description>
      <![CDATA[ 
         A more recent picture of the property taken by the Borelli family.  The property is listed in the 
         National and New Jersey Registers of Historic Places.
      ]]>
      </description>
      <date>1950 circa</date>
      <images>
         <img src="1749a.jpg" />
      </images>
   </photo>

   <photo cid="c1411" donatedBy="Saint Johns Catholic Church">
      <name metadata="saint johns catholic church">Saint Johns Church</name>
      <description>
      <![CDATA[ 
         A more recent picture of the property taken by the Borelli family.  The property is listed in the 
         National and New Jersey Registers of Historic Places.
      ]]>
      </description>      
      <date>1921</date>
   </photo>

   <photo cid="c2003" donatedBy="Linda Choo">
      <name metadata="bergenfield elementary school">Bergenfield School</name>
      <description>
      <![CDATA[ 
         The No. 5 Public School, a.k.a. Bergenfield School
      ]]>
      </description>
      <date>1920 circa</date>
      <images>
         <img src="2003a.jpg" />
         <img src="2003b.jpg" />
      </images>
   </photo>

   <photo cid="c2078" donatedBy="Maria Giodelli">
      <name metadata="coopers pond water">Coopers Pond</name>
      <description>
      <![CDATA[ 
         A favorite spot where we used to go hang out as kids.  The picture shows my brothers Robert and Michael.
      ]]>
      </description>
      <date>May 4, 1941</date>
      <images>
         <img src="2078a.jpg" />
      </images>
   </photo>

   <photo cid="c2079" donatedBy="Linda Uffington">
      <name metadata="watch timekeeping pocket railway">Pocket Watch</name>
      <description>
      <![CDATA[ 
         A more recent picture of the property taken by the Borelli family.  The property is listed in the 
         National and New Jersey Registers of Historic Places.
      ]]>
      </description>
      <date>1870 circa</date>
      <images>
         <img src="2079a.jpg" />
         <img src="2079b.jpg" />
      </images>
   </photo>

   <photo cid="c3233">
      <name metadata="hotel">Bergenfield Hotel</name>
      <description>
      <![CDATA[ 
         The Knollfield Hotel was known as the Bergenfield Hotel.  The property is listed in the 
         National and New Jersey Registers of Historic Places.
      ]]>
      </description>
      <date>circa 1920</date>
   </photo>

   <photo cid="c3433">
      <name metadata="sweeney coal fuel">Sweeney Coal</name>
      <description>
      <![CDATA[ 
         Sweeny Fuel Company located near New Bridge Road and railroad tracks.
      ]]>
      </description>
      <date>1920</date>
      <images>
         <img src="3433a.jpg" />
         <img src="3433b.jpg" />
         <img src="3433c.jpg" />
      </images>
   </photo>

</catalog>

 

And the DTD file:

 

<!--
   New Perspectives on XML
   Tutorial 2
   Case Problem 1

   Catalog of photos from the Our Lady of Bergen Historical Society
   Author: <removed>
   Date:   1/28/2016

   Filename:         photos.dtd
   Supporting File:  photos.xml
-->
<!DOCTYPE catalog [
    <!ELEMENT catalog (photo+)>
    <!ATTLIST type catalog NMTOKEN #REQUIRED>

    <!ELEMENT photo (name, description, date, images?)>
    <!ATTLIST cid photo ID #REQUIRED>
    <!ATTLIST donatedBy photo CDATA #IMPLIED>

    <!ELEMENT name (#PCDATA)>
    <!ATTLIST metadata name NMTOKENS #REQUIRED>

    <!ELEMENT description (#PCDATA)>
    <!ELEMENT date (#PCDATA)>

    <!ELEMENT images (img+)>
    <!ELEMENT img (EMPTY)>
    <!ATTLIST src img CDATA #REQUIRED>
    ]>

Edited by Perfect72
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
<!--
   New Perspectives on XML
   Tutorial 2
   Case Problem 1
   Catalog of photos from the Our Lady of Bergen Historical Society
   Author: <removed>
   Date:   1/28/2016
   Filename:         photos.dtd
   Supporting File:  photos.xml
-->
<!DOCTYPE catalog [
    <!ELEMENT catalog (photo+)>
    <!ATTLIST type catalog NMTOKEN #REQUIRED>
    <!ELEMENT photo (name, description, date, images?)>
    <!ATTLIST cid photo ID #REQUIRED>
    <!ATTLIST donatedBy photo CDATA #IMPLIED>
    <!ELEMENT name (#PCDATA)>
    <!ATTLIST metadata name NMTOKENS #REQUIRED>
    <!ELEMENT description (#PCDATA)>
    <!ELEMENT date (#PCDATA)>
    <!ELEMENT images (img+)>
    <!ELEMENT img (EMPTY)>
    <!ATTLIST src img CDATA #REQUIRED>
]>

Should be:

<!--
   New Perspectives on XML
   Tutorial 2
   Case Problem 1
   Catalog of photos from the Our Lady of Bergen Historical Society
   Author: <removed>
   Date:   1/28/2016
   Filename:         photos.dtd
   Supporting File:  photos.xml
-->
<!ELEMENT catalog (photo+)>
<!ATTLIST type catalog NMTOKEN #REQUIRED>
<!ELEMENT photo (name, description, date, images?)>
<!ATTLIST cid photo ID #REQUIRED>
<!ATTLIST donatedBy photo CDATA #IMPLIED>
<!ELEMENT name (#PCDATA)>
<!ATTLIST metadata name NMTOKENS #REQUIRED>
<!ELEMENT description (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT images (img+)>
<!ELEMENT img (EMPTY)>
<!ATTLIST src img CDATA #REQUIRED>

The doctype is only needed when you put the dtd inline in the xml file.

Source: http://stackoverflow.com/questions/5455394/problem-with-external-referenced-dtd-in-xml

 

Also you're missing quite a few attribute declarations :rofl:

Link to comment
Share on other sites

  • 0

Woops, I forgot I did end up removing that after figuring it out, but still keep getting errors. Is it the missing declarations?  I am completely new to XML and like I said, my teacher isn't much help besides just reading passages from the book which I'm not very good at learning with.

Link to comment
Share on other sites

  • 0
4 minutes ago, Perfect72 said:

Woops, I forgot I did end up removing that after figuring it out, but still keep getting errors. Is it the missing declarations?  I am completely new to XML and like I said, my teacher isn't much help besides just reading passages from the book which I'm not very good at learning with.

Your teacher isn't much help teaching you something as defunct as DTD.  Can I ask why you aren't learning XSD instead?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.