Part 1, Learning about DTDs: Create a DTD for courses in a university. Each cour
ID: 650349 • Letter: P
Question
Part 1, Learning about DTDs: Create a DTD for courses in a university. Each course element should have child elements department, course_name, course_number, instructor, course_type, time, and room. The course_type element must have attributes lab and lecture, each of which may have values true or false. Don't forget that you will need a declaration for your root element, too. You could name your root element something like "catalog" or "schedule." Name your DTD l6p1.dtd.
Validate your DTD using the DTD validator here: http://www.validome.org/grammar/ You will need to click the DTD radio button before clicking the "validate" button. The URL for your DTD will look something like http://weblab.spsu.edu/~bbrown/l6p1.dtd. Correct any errors in your DTD.
Part 2, How DTDs and XML documents go together: Create an XML document named l6p2.xml with at least three instances of the "course" element defined in the DTD of Part 1. At least one of the courses must have a lab component.
Put a DOCTYPE header in your XML file referring to your DTD. Assuming that your XML root element is named <courses>, the first three lines of your XML file will now look something like this:
(Of course, you must put your user ID instead of mine in the link to the DTD, right?)
Validate your document using the Validome validator at http://www.validome.org/xml/validate/. You will be validating by URL. Correct any errors.
Display your document using the Firefox browser.
The Validome validator displays a link right under the "Document is valid" box. Place that link, with the text "L6P2" on your index document. I will use the link for testing.
Part 3; Validating form data: Make a copy of the order form from lab exercise 4 and name it l6p3.php. Remove the JavaScript code to calculate the total price. Add JavaScript code to produce an error message and suppress submission of the form if any quantity field contains non-numeric data. (It's OK for a quantity to be empty, but if it's non-empty, it must have only numbers.) Add an action= attribute to your <form> tag to submit the form to http://weblab.spsu.edu/formtest.php. Test that the form is submitted correctly when the quantities are numeric or empty, and that an error message is produced otherwise. (Regular expressions are your friend. Anything that's not a digit is bad. What is the predefined class for non-digits?)
Add to your index page a link to your new order form.
Part 4; Using PHP to generate forms: To your order form from Part 3, add input elements for customer name and address if they're not already there. The "state" part of the address must be a select list (also called a "pulldown menu") to allow the person placing the order to choose his or her state. Don't type all fifty states, but supply at least Georgia, Alabama and Florida. Put the names of the states in an PHP array and use PHP code to create the drop-down dynamically. (This will still be named l7p3.php; you're just adding to something you've already tested.)
You will find an example of creating a select list for states in the class slides covering HTML forms. You are going to create the drop-down dynamically, and not by hard-coding it. This part of the assignment is a fair example of something you might do with PHP in "real life." Instead of an array, you would use a database call, so if we suddenly add another state to the U.S. (or your company suddenly adds another state to its service area) a change to the database automatically (and immediately) changes what people see in the form. For this assignment, you're loading states from an array. We'll get them from a database in the next assignment.
You do not need a special link on your index page for Part 2; I will test Part 2 at the same time I test Part 1.
Explanation / Answer
Part 1)
<!ELEMENT courses (department, course_name, course_number, instructor, course_type, time,room)>
<!ELEMENT department (#PCDATA)>
<!ELEMENT course_name (#PCDATA)>
<!ELEMENT course_number (#PCDATA)>
<!ELEMENT instructor (#PCDATA)>
<!ELEMENT course_type (lab,lecture)>
<!ELEMENT time (#PCDATA)>
<!ELEMENT room (#PCDATA)>
<!ATTLIST course_type lab CDATA "true | false">
<!ATTLIST course_type lecture CDATA "true | false">