XML Video Tutorial 4

DTD Video TutorialIn this part of my XML Video Tutorial, I cover Document Type Definitions (DTD). DTDs are used to define the markup for your XML files.

We use DTD files to make sure data is valid and so multiple people can work together in a standardized way.

It sounds really complicated, but you are just defining what elements are required in the XML file and what type of data each element must have. The code after the video will help you learn.

If you like videos like this, tell Google [googleplusone]

Always share

Code From the Video

<?xml version="1.0" encoding="UTF-8"?>
<!-- You would surround everything with <!DOCTYPE tvshow [ and ]> 
	if this was in your XML file -->

<!-- Document Type Definition (DTD) defines the makeup of a XML file -->

<!-- Use a DTD to make sure data is valid and so multiple people can work
together in a standard way -->

<!-- DOCTYPE defines the root for the document -->

<!ELEMENT tvshow (show)+>

<!-- Elements without a quantifier must appear only once -->

<!-- The show element must have only these elements & they must be in order -->

<!-- Must have 1 network, but can have many because of + -->

<!-- Doesn't require viewers or a poster, but can only have 1 because of ? -->

<!-- If I would want an element to contain content and child elements
I would proceed it with a * -->

<!-- The OR | states that you must have either a end_date or a next_episode --> 

<!ELEMENT show (name, release, network+, description, actors, poster?, 
	viewers?, (end_date | next_episode))>
<!-- #PCDATA (Parsed Character Data) is used to denote the element contains text -->

<!-- #PCDATA can't contain any other elements -->

<!-- #PCDATA is parsed meaning entities like < are converted to < -->

<!-- Don't use < > & " or ' in #PCDATA -->
<!-- #CDATA is character data that isn't parsed -->

<!-- To allow a user to enter what ever they like in show follow everything
	with a * like this
	<!ELEMENT show (name | release | network | poster |
	description | actors | viewers | end_date | next_episode)*> -->
<!-- You can allow a user to enter data or child elements like this
	<!ELEMENT name (#PCDATA | nickname)*> -->
<!-- You can allow any type of data like this <!ELEMENT name ANY> -->

<!-- Define attributes like this <!ATTLIST elementWithTheAttribute attributeName dataType defaultValue -->

<!-- Data Types: CDATA - Character Data, Enumerated List - (value1|value2|...),
	ID - A unique ID -->
<!-- An ID is unique and can't be used anywhere else in the document -->
<!ATTLIST name id_code ID #REQUIRED>

<!ELEMENT release (#PCDATA)>

<!ELEMENT network (#PCDATA)>
<!ATTLIST network country CDATA #REQUIRED>

<!ELEMENT description (#PCDATA)>

<!-- List child elements if the element contains children -->

<!-- * can be used for elements that can occur zero or many times -->

<!ELEMENT actors (actor)*>
<!ELEMENT actor (real_name, character)>

<!ELEMENT real_name (#PCDATA)>
<!ELEMENT character (#PCDATA)>
<!ATTLIST character profession CDATA #IMPLIED>

<!-- You can have empty elements using EMPTY: <!ELEMENT br EMPTY> The <br />
element is a good example of an element that does something, but doesn't contain content -->

<!-- #IMPLIED means a value isn't required -->

<!-- It would be better form to put the data in href in the poster element.
	Attributes should be used to describe data versus what you'd want to display -->

<!ATTLIST poster width CDATA #IMPLIED>
<!ATTLIST poster height CDATA #IMPLIED>

<!-- You can reference a unique ID using a IDREF -->

<!-- A IDREFS can contain many unique IDs like this <!ATTLIST poster show_ids IDREFS #IMPLIED> -->

<!-- You'd add these IDs like this <poster show_ids="show_100 show_101"> -->

<!ATTLIST poster show_id IDREF #IMPLIED>

<!-- You can also assign default values by just supplying it in the attribute definition -->

<!-- You could also fix this value <!ATTLIST viewers units CDATA #FIXED "million"> -->

<!-- You can also use an enumerated list <!ATTLIST viewers units (thousand | million) #IMPLIED> -->

<!ELEMENT viewers (#PCDATA)>
<!ATTLIST viewers units CDATA "million">

<!ELEMENT end_date (#PCDATA)>
<!ELEMENT next_episode (#PCDATA)>

<!-- You can also force an attribute to only contain letters, numbers,
	hyphens, underscores, or periods like this 
	<!ATTLIST character profession NMTOKEN #IMPLIED> -->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tvshow SYSTEM "tvshow1.dtd" >
    <name id_code="idvalue0">name</name>
    <network country="">network</network>
    <poster height="" href="" show_id="idvalue0" width=""/>
    <viewers units="million">viewers</viewers>

20 Responses to “XML Video Tutorial 4”

  1. mr.roshik says:

    Would you please post an article on 960 grid system as css framework and How to make responsive template ?

    • admin says:

      I don’t use that system. I just draw everything in Illustrator and then measure everything out. I’ll look into whether I find this grid helpful. Thanks for pointing it out

  2. mr.roshik says:

    How to clean laptop’s screen without any spot ? any idea bro ?

  3. mr.roshik says:

    Do u have any odesk account ? i want to customize my profile like u 😀

  4. mr.roshik says:

    how to switch css stylesheet with jquery? bro if u dont understand my question pls check this tutorial but it doesnt make sense or difficult. would u please post an tutorial on jquery stylesheet switcher?


  5. mr.roshik says:

    Thanks bro, im so hapy that i’ve met a friendly person like you.

    • admin says:

      I’m very happy that you like my website. I continue to get less search traffic every month. It is people like you that keep my website going 🙂

  6. Ammy says:

    Plz Tell me how to map XML DTD file into the Database using Java

  7. mel says:

    these tutorials are awesome. If we want to check out the XML file, do we need to add in an XSL to check it out? In firefox, I get this message: This XML file does not appear to have any style information associated with it.

    • Derek Banas says:

      Thank you 🙂 Sorry about the error. There are actually 2 files on this page. It may have seemed as if there was only one because they aren’t separated. I hope that helps 🙂

  8. webdesign says:

    Veryyyy good, thanks for sharing

Leave a Reply

Your email address will not be published.