Results 1 to 4 of 4

Thread: Help with Document Type Definition (DTD)

  1. #1
    Join Date
    Dec 2013

    Help with Document Type Definition (DTD)

    So I have an element called web_site that must contain no text but it has an attribute URL that is always the same. Is something around these lines correct?

    <!ELEMENT web_site EMPTY)>
    <!ATTLIST web_site url CDATA #REQUIRED>

  2. #2
    Join Date
    Jul 2010
    Your best way of knowing is to use an online XML validator

    1. Create your XML document
    2. Write your DTD
    3. Insert it DTD at the right spot in the XML document
    4. Run the validator. It will check your DTD against your markup

    If there are errors, then continue editing the DTD to fit your markup, assuming your markup is what you want. I have often found out that markup is edited while I edit the DTD (going back and forth).

    I see multiple errors in your DTD now. One is an unmatched right-hand parenthesis (')') in your DTD. No parenthesis is need with the EMPTY declaration.

    You are also missing the root element/node definition: "<!DOCTYPE root [ ..... ]>", which must contain all your declarations.

    You should show us your "well-formed" (not valid) XML markup/content. Well-formed is just the markup without any DTD or xml-schema.

    Suppose your root element is named 'root'. The following is both a well-formed and valid(ated) XML document for what you want

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE root [
    <!ELEMENT root (web_site)>
    <!ELEMENT web_site EMPTY>
    <!ATTLIST web_site url CDATA #REQUIRED>
     <web_site url="http://a.website.com" />
    Note that you should probably be learning to make XML Schema rather than using the DTD. DTD is insufficient for specifying limitations on attribute values and certain content.

    For example, the DTD will not verify that the attribute value for the URL is a valid URL string. The XML schema can check for a valid URL type string.

    Do a google search on "xml schema." W3Schools.com will give you a taste. You can also go to W3.org to read the specification for making XML schema. Plenty of ebooks and PDFs are written on producing XML schema. Don't bother writing DTDs unless it is for XML document you will only write once and you need the validation for something like PHP or Javascript code to make a DOM object.
    Last edited by seniseven; 12-30-2013 at 10:34 AM.

  3. #3
    Join Date
    Dec 2013
    Firstly, thank you for that great reply. I have used the xmlvalidator to remove any errors. This is currently what I have at the moment.

    <?xml version="1.0" encoding= "UTF-8" standalone ="no"?>
    <!DOCTYPE books [
    <!ELEMENT books (book*)>
    <!ELEMENT book (author+, title, isbn, price, publisher, year, web_site?, description?) >
    <!ELEMENT author (given_name+, surname) >
    <!ELEMENT given_name (#PCDATA) >
    <!ELEMENT surname (#PCDATA) >
    <!ELEMENT title (#PCDATA) >
    <!ELEMENT isbn (#PCDATA) >
    <!ELEMENT price (#PCDATA) >
    <!ELEMENT publisher (location, pub_name) >
    <!ELEMENT location (#PCDATA) >
    <!ELEMENT pub_name (#PCDATA) >
    <!ELEMENT year (#PCDATA) >
    <!ELEMENT web_site EMPTY>
    <!ATTLIST web_site url  CDATA #REQUIRED>
    <!ATTLIST book format (paperback|hardcover)  #REQUIRED >
    <!ATTLIST book condition (worn|reasonable|good|very_good) "good"  >
    <!ELEMENT description ANY >
       <book format="paperback" condition="worn">
    	  <surname> Raskin </surname>
    	 <title> The Humane Interface</title>
    		<pub_name> Addison Wesley</pub_name>
    	 <web_site url="http://eu,wiley.com/0012345678/" />
    	 <description> A mixture of theory and practical guidelines for GUI design. It now 
    			has a wikipedia entry at
    			<web_site url="http://wn.wikipedia.org/wiki/the_humane_interface" />, and
    			also features on Google books (<web_site
    			url="http://books.google.co.uk/books" />.</description>

  4. #4
    Thanks for your sharing! Good stuff...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center