• 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
https://www.neowin.net/forum/topic/1287978-issues-validating-xml-with-dtd/
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:

  • 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.

  • 0
  On 06/02/2016 at 17:02, 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.

Expand  

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

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

    • No registered users viewing this page.
  • Posts

    • Sony announces new State of Play games showcase for tomorrow by Pulasthi Ariyasinghe Game publishers love to get their showcases and announcements to happen in June, and following many other companies, Sony has now thrown its hat into the ring as well. There's not long to wait either. The PlayStation maker will be hosting a showcase of its own tomorrow, June 4, focused on titles coming to its platforms. The June State of Play will go live on Wednesday, June 4, at 2pm PT / 5pm ET / 11pm CEST. Fans can catch the show across Sony's YouTube and Twitch channels live. It seems that unlike previous State of Play shows, a Japanese broadcast will not be happening, with only an English stream being confirmed this time. "Watch live for news and updates on must-play games coming to PS5," says the announcement today. "The show highlights a selection of great games from creators across the globe." Other than that, Sony has not given any hints or teasers about what fans can expect to see at the show. We still may get new looks at upcoming first-party titles like Ghost of Yotei from Ghost of Tsushima developer Sucker Punch Productions, Marathon from Destiny studio Bungie, and maybe even Insomniac’s Wolverine title that's set in its Spider-Man universe. Sony still has some live service titles in development that may get some time in the spotlight here too. As always, more PC ports have a chance of being revealed here as well, continuing Sony's multiplatform venture. Following the State of Play showcase, Summer Game Fest will officially kick off with its own event later this week. Microsoft is also preparing to go live with its own Xbox Games Showcase, with a separate Direct stream focused on its next RPG release, The Outer Worlds 2 from Obsidian Entertainment.
    • Hello All Every day MS App store lists the same apps with update available,  select update all, and then think all is fine, and next day same list shows up again.  Any advice on how to fix this for good?   Should i resort to clean install? On the AMD Ryzen 7 7700X Desktop    
    • Battery life for devices like this should - at least - a week. It's not a bl**dy phone you need to charge every day. 'rolls eyes'
  • Recent Achievements

    • Week One Done
      Adam Todd earned a badge
      Week One Done
    • Contributor
      Ed B went up a rank
      Contributor
    • One Month Later
      moporcho earned a badge
      One Month Later
    • One Month Later
      Parotel earned a badge
      One Month Later
    • Reacting Well
      Cryptecks earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      195
    2. 2
      snowy owl
      139
    3. 3
      ATLien_0
      132
    4. 4
      Xenon
      120
    5. 5
      +FloatingFatMan
      104
  • Tell a friend

    Love Neowin? Tell a friend!