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
Using XML Validators
An XML validator checks your XML to make sure it's well formed and valid, giving you feedback if there's a problem. Here's a starter list of some validators on the Internet—note that your XML document must be online to use any of these validators, except for the Scholarly Technology Group validator, which can upload your XML document from your hard disk:
- http://validator.w3.org/— This is the official W3C HTML validator. It's designed for HTML, but also includes some XML support.
- http://tidy.sourceforge.net/— Tidy is a popular utility for cleaning up and repairing Web pages. It also includes some support for XML.
- http://www.xml.com/pub/a/tools/ruwf/check.html— This is XML.com's XML validator, based on the Lark XML processor.
- http://www.ltg.ed.ac.uk/~richard/xml-check.html— The Language Technology Group at the University of Edinburgh's validator, based on the RXP XML parser.
- http://www.stg.brown.edu/service/xmlvalid/— The home of the very useful XML validator from the Scholarly Technology Group at Brown University. This is one of only a few online XML validators that allows you to check XML documents that are not online—you can browse to your document on your hard disk and this validator will upload it.
You can see the Scholarly Technology Group's validator at work in Figure 2.6. To give it something to chew on, we'll send it the XML document from yesterday's work, where we've exchanged the <message> and </heading> tags like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="ch01_04.css"?>
<!DOCTYPE document [
<!ELEMENT document (heading, message)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT message (#PCDATA)>
]>
<document>
<heading>
Hello From XML
<message>
</heading>
This is an XML document!
</message>
</document>
Figure 2.6 Using an XML validator.
Note also that to let the validator actually validate the document, you have to let it know what the document's syntax is. To do that, we've included a DTD in this document specifying that syntax (DTDs are coming up in Day 4, "Creating Valid XML Documents: Document Type Definitions," and Day 5, "Handling Attributes and Entities in DTDs."
When you click the Validate button in the validator, you get the results that appear in Figure 2.7. As you see in the figure, the validator indicates that these two tags are indeed swapped, causing a validation error.
Figure 2.7 The results from an XML validator.
There's a built-in validator for documents with XML schema in Microsoft's Visual Studio .NET, and Internet Explorer can also validate documents with XML schemas. (As you'll see in more depth in Day 6, "Creating Valid XML Documents: XML Schemas," Visual Studio lets you generate an XML schema for an XML document with the XML, Create Schema menu item.) You can use the XML, Validate XML Data menu item to validate an XML document that uses a schema, as you see in Figure 2.8. Note the text No validation errors were found at the lower left, which is Visual Studio .NET's subtle way of telling you that the document is OK.
Figure 2.8 XML validation in Visual Studio .NET.
That gives you a good overview of the kinds of tools available to help you develop your XML these days—editors, browsers, and validators. Now it's time to get down to brass tacks and understand what makes an XML document tick, piece by piece.
Creating XML Documents Piece by Piece | Next Section

Account Sign In
View your cart