Sams Teach Yourself XML in 21 Days
- Table of Contents
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Introduction
- Part I: At a Glance
- Day 1. Welcome to XML
- Day 2. Creating XML Documents
- Day 3. Creating Well-Formed XML Documents
- Day 4. Creating Valid XML Documents: DTDs
- Declaring Attributes in DTDs
- Day 6. Creating Valid XML Documents: XML Schemas
- Day 7. Creating Types in XML Schemas
- Part I. In Review
- Day 8. Formatting XML by Using Cascading Style Sheets
- Day 9. Formatting XML by Using XSLT
- Day 10. Working with XSL Formatting Objects
- Part II. In Review
- Part III: At a Glance
- Day 11. Extending HTML with XHTML
- Day 12. Putting XHTML to Work
- Day 13. Creating Graphics and Multimedia: SVG and SMIL
- Day 14. Handling XLinks, XPointers, and XForms
- Part III. In Review
- Part IV: At a Glance
- Day 15. Using JavaScript and XML
- Day 16. Using Java and .NET: DOM
- Day 17. Using Java and .NET: SAX
- Day 18. Working with SOAP and RDF
- Part IV. In Review
- Part V: At a Glance
- Day 19. Handling XML Data Binding
- Day 20. Working with XML and Databases
- Day 21. Handling XML in .NET
- Part V. In Review
- Appendix A. Quiz Answers
Workshop
This workshop tests whether you understand the concepts discussed today. It's a good idea to make sure you can answer these questions before pressing on to tomorrow's work. Answers to the quiz can be found in Appendix A, "Quiz Answers."
Quiz
- What's wrong with this XML document?
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE document [ <!ELEMENT document (employee)*> <!ELEMENT employee (hiredate, name)> ]> <document> <employee> <hiredate>October 15, 2005</hiredate> <name> Grace Kelly </name> </employee> </document> - Where do you see a problem with this XML document?
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE document [ <!ELEMENT document (employee)*> <!ELEMENT employee (name, hiredate)> <!ELEMENT name (#PCDATA)> <!ELEMENT hiredate (#PCDATA)> ]> <document> <employee> <hiredate>October 15, 2005</hiredate> <name> Grace Kelly </name> </employee> </document> - What error is in this XML document?
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE document [ <!ELEMENT document (employee)*> <!ELEMENT employee (hiredate+ | name+)> <!ELEMENT hiredate (#PCDATA)> <!ELEMENT name (#PCDATA)> ]> <document> <employee> <hiredate>October 15, 2005</hiredate> <name> Grace Kelly </name> </employee> </document> - There's a problem in this XML document, too. What is it?
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE document [ <!ELEMENT document (employee)?> <!ELEMENT employee (hiredate+, name*, phone+)> <!ELEMENT hiredate (#PCDATA)> <!ELEMENT name (#PCDATA)> <!ELEMENT phone (#PCDATA)> ]> <document> <employee> <hiredate>October 15, 2005</hiredate> <name> Grace Kelly </name> <phone> 555.8888 </phone> </employee> <employee> <hiredate>October 16, 2005</hiredate> <name> Myrna Loy </name> <name> Muriel Blandings </name> <phone> 555.9999 </phone> </employee> </document> - What's wrong with this XML document?
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE document SYSTEM "employee.dtd"> <document> <employee> <name> Grace Kelly </name> <hiredate>October 15, 2005</hiredate> </employee> </document>
Exercises
- Create a new XML document that holds the names of your relatives by using elements such as <brother>, <sister>, <mother>, and <father>, as well as <name>, <age>, and <address> elements. Next, add a DTD to the document and use an XML validator such as the Scholarly Technology Group's XML validator, at http://www.stg.brown.edu/service/xmlvalid, to check whether your document is valid. Alternatively, add to the well-formed XML document you created in Exercise 1 at the end of yesterday's discussion a DTD that holds the available menu items and their prices at a favorite restaurant of yours.
- Convert the XML document you created in Exercise 1 to make the DTD external. If you can upload the external DTD file to a Web server and include its URI in the <!DOCTYPE> element (for example, <!DOCTYPE document SYSTEM "http://www.server.com/username/relatives.dtd">), use an online XML validator such as the Scholarly Technology Group's XML validator to check the new document's validity.
Declaring Attributes in DTDs | Next Section

Account Sign In
View your cart