So I am working on this XML project to create a small list of favorite DVDs, etc. Maybe I missed it (or that I may have not gotten this far in my reading) but in my DTD I want to restrict movie_review to only allow (G | PG | PG-13 | R | NC-17)... but for some reason it's not working... here's what I have so far... that has been validated.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE DVDLibrary[
  <!ELEMENT DVDLibrary (DVD)*>
  
  <!ELEMENT DVD (title, genre, movie_rating, viewer_rating, summary, year, director, runtime, studio, cast)>
  <!ATTLIST DVD id ID #REQUIRED>

  <!ELEMENT title (#PCDATA)>

  <!ELEMENT genre (#PCDATA)>

  <!ELEMENT movie_rating (#PCDATA)>

  <!ELEMENT viewer_rating (#PCDATA)>

  <!ELEMENT summary (#PCDATA)>
  <!ELEMENT year (#PCDATA)>
  <!ELEMENT director (#PCDATA)>
  <!ELEMENT runtime (#PCDATA)>
  <!ELEMENT studio (#PCDATA)>

  <!ELEMENT cast (actor)*>
  <!ELEMENT actor (firstName, lastName)*>
  <!ATTLIST actor idnum ID #REQUIRED>
  <!ELEMENT firstName (#PCDATA)>
  <!ELEMENT lastName (#PCDATA)>


]>
<DVDLibrary>
  <DVD id ="DVD1">
    <title>Serenity</title>
    <genre>Sci-Fi</genre>
    <movie_rating>PG-13</movie_rating>
    <viewer_rating>5</viewer_rating>
    <summary>
      Serenity is a space western that takes place after the last episode of the Fox television series Firefly. Set in 2518,
      Serenity is the story of Captain Malcom "Mal" Reynolds and his crew aboard his Firefly Class cargo ship named "Serenity". Mal and his crew are on the run
      from the totalitarian Alliance government since he harbored two fugitives of the Alliance, one with a deadly secret. Now an Alliance assassin in after that one passenger, River Tam,
      and Mal finds himself locked in a battle to uncover the truth of River's past while escaping the relentless Alliance regime who will stop at nothing to get her back.
    </summary>
    <year>2005</year>
    <director>Joss Whedon</director>
    <runtime>119 min</runtime>
    <studio>Universal Pictures</studio>
    <cast>
      <actor idnum="SE01">
        <firstName>Nathan</firstName>
        <lastName>Fillion</lastName>
      </actor>
      <actor idnum="SE02">
        <firstName>Alan</firstName>
        <lastName>Tudyk</lastName>
      </actor>
      <actor idnum="SE03">
        <firstName>Adam</firstName>
        <lastName>Baldwin</lastName>
      </actor>
      <actor idnum="SE04">
        <firstName>Sean</firstName>
        <lastName>Maher</lastName>
      </actor>
      <actor idnum="SE05">
        <firstName>Ron</firstName>
        <lastName>Glass</lastName>
      </actor>
      <actor idnum="SE06">
        <firstName>Gina</firstName>
        <lastName>Torrest</lastName>
      </actor>
      <actor idnum="SE07">
        <firstName>Morena</firstName>
        <lastName>Baccarin</lastName>
      </actor>
      <actor idnum="SE08">
        <firstName>Jewel</firstName>
        <lastName>Staite</lastName>
      </actor>
      <actor idnum="SE09">
        <firstName>Summer</firstName>
        <lastName>Glau</lastName>
      </actor>
    </cast>
  </DVD>
<DVD id="DVD2"> 
    <title>Total Recall</title>
    <genre></genre>
    <movie_rating></movie_rating>
    <viewer_rating></viewer_rating>
    <summary></summary>
    <year></year> 
    <director></director> 
    <runtime></runtime> 
    <studio></studio> 
    <cast>
	<actor idnum="TR01">
	  <firstName></firstName>
	  <lastName></lastName>
	</actor>
    </cast>  
</DVD> 
</DVDLibrary>
<-- more after this -->

I try varions like this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE DVDLibrary[
  <!ELEMENT DVDLibrary (DVD)*>
  
  <!ELEMENT DVD (title, genre, movie_rating, viewer_rating, summary, year, director, runtime, studio, cast)>
  <!ATTLIST DVD id ID #REQUIRED>

  <!ELEMENT title (#PCDATA)>

  <!ELEMENT genre (#PCDATA)>

  <!ELEMENT movie_rating (#PCDATA)>
  <!ATTLIST movie_rating movie_rating (G | PG | PG-13 | R | NC-17) >

  <!ELEMENT viewer_rating (#PCDATA)>

  <!ELEMENT summary (#PCDATA)>
  <!ELEMENT year (#PCDATA)>
  <!ELEMENT director (#PCDATA)>
  <!ELEMENT runtime (#PCDATA)>
  <!ELEMENT studio (#PCDATA)>

  <!ELEMENT cast (actor)*>
  <!ELEMENT actor (firstName, lastName)*>
  <!ATTLIST actor idnum ID #REQUIRED>
  <!ELEMENT firstName (#PCDATA)>
  <!ELEMENT lastName (#PCDATA)>
]>

and getting this error...

Open quote is expected for attribute "rating" associated with an element type "movie_rating".

Am I even in the ballpark on this one?

see here Enumerated Attribute Values
http://www.w3schools.com/DTD/dtd_attributes.asp
so make xml ready

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE DVDLibrary[
  <!ELEMENT DVDLibrary (DVD)*>
  
  <!ELEMENT DVD (title, genre, movie_rating, viewer_rating, summary, year, director, runtime, studio, cast)>
  <!ATTLIST DVD id ID #REQUIRED>

  <!ELEMENT title (#PCDATA)>

  <!ELEMENT genre (#PCDATA)>

  <!ELEMENT movie_rating EMPTY>
<!ATTLIST movie_rating movie_rating (G | PG | PG-13 | R | NC-17) "G">
  <!ELEMENT viewer_rating (#PCDATA)>

  <!ELEMENT summary (#PCDATA)>
  <!ELEMENT year (#PCDATA)>
  <!ELEMENT director (#PCDATA)>
  <!ELEMENT runtime (#PCDATA)>
  <!ELEMENT studio (#PCDATA)>

  <!ELEMENT cast (actor)*>
  <!ELEMENT actor (firstName, lastName)*>
  <!ATTLIST actor idnum ID #REQUIRED>
  <!ELEMENT firstName (#PCDATA)>
  <!ELEMENT lastName (#PCDATA)>


]>
<DVDLibrary>
  <DVD id ="DVD1">
    <title>Serenity</title>
    <genre>Sci-Fi</genre>
    <movie_rating movie_rating="R"></movie_rating>
    <viewer_rating>5</viewer_rating>
    <summary>
      Serenity is a space western that takes place after the last episode of the Fox television series Firefly. Set in 2518,
      Serenity is the story of Captain Malcom "Mal" Reynolds and his crew aboard his Firefly Class cargo ship named "Serenity". Mal and his crew are on the run
      from the totalitarian Alliance government since he harbored two fugitives of the Alliance, one with a deadly secret. Now an Alliance assassin in after that one passenger, River Tam,
      and Mal finds himself locked in a battle to uncover the truth of River's past while escaping the relentless Alliance regime who will stop at nothing to get her back.
    </summary>
    <year>2005</year>
    <director>Joss Whedon</director>
    <runtime>119 min</runtime>
    <studio>Universal Pictures</studio>
    <cast>
      <actor idnum="SE01">
        <firstName>Nathan</firstName>
        <lastName>Fillion</lastName>
      </actor>
      <actor idnum="SE02">
        <firstName>Alan</firstName>
        <lastName>Tudyk</lastName>
      </actor>
      <actor idnum="SE03">
        <firstName>Adam</firstName>
        <lastName>Baldwin</lastName>
      </actor>
      <actor idnum="SE04">
        <firstName>Sean</firstName>
        <lastName>Maher</lastName>
      </actor>
      <actor idnum="SE05">
        <firstName>Ron</firstName>
        <lastName>Glass</lastName>
      </actor>
      <actor idnum="SE06">
        <firstName>Gina</firstName>
        <lastName>Torrest</lastName>
      </actor>
      <actor idnum="SE07">
        <firstName>Morena</firstName>
        <lastName>Baccarin</lastName>
      </actor>
      <actor idnum="SE08">
        <firstName>Jewel</firstName>
        <lastName>Staite</lastName>
      </actor>
      <actor idnum="SE09">
        <firstName>Summer</firstName>
        <lastName>Glau</lastName>
      </actor>
    </cast>
  </DVD>
<DVD id="DVD2"> 
    <title>Total Recall</title>
    <genre></genre>
    <movie_rating></movie_rating>
    <viewer_rating></viewer_rating>
    <summary></summary>
    <year></year> 
    <director></director> 
    <runtime></runtime> 
    <studio></studio> 
    <cast>
	<actor idnum="TR01">
	  <firstName></firstName>
	  <lastName></lastName>
	</actor>
    </cast>  
</DVD> 
</DVDLibrary>

Thanks I understand it now!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.