Validating Against a DTD

How do you really know if your XML document is valid? One way is to check it with an XML validator, and there are plenty out there to choose from. As we saw in Chapter 1, validators are packages that will check your XML and give you feedback. Here's a list of some of the XML validators on the Web:

  • W3C XML validator (validator.w3.org/) This is the official W3C HTML validator. Although it's officially for HTML, it also includes some XML support. Your XML document must be online to be checked with this validator.

  • Tidy (www.w3.org/People/Raggett/tidy/) Tidy is a beloved utility for cleaning up and repairing Web pages, and it includes limited support for XML. Your XML document must be online to be checked with this validator.

  • XML.com (www.xml.com/xml/pub/tools/ruwf/check.html) This is XML.com's XML validator based on the Lark processor. Your XML document must be online to be checked with this validator.

  • Language Technology Group (www.ltg.ed.ac.uk/~richard/xml-check.html) The Language Technology Group at the University of Edinburgh has this validator, based on the RXP parser. Your XML document must be online to be checked with this validator.

  • STG XML Validator (http://www.stg.brown.edu/service/xmlvalid/) This excellent XML validator is from the Scholarly Technology Group at Brown University. This is the only online XML validator that I know of that allows you to check XML documents that are not online; you can use the Web page's file upload control to specify the name of the file on your hard disk that you want to have uploaded and checked.

To see one of these online validators at work, take a look at Figure 1-11 back in Chapter 1. There, I'm asking the XML validator from the Scholarly Technology Group to validate greeting.xml after I've added a DTD and purposely exchanged the order of the <MESSAGE> and </GREETING> tags:

 <?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE DOCUMENT [     <!ELEMENT DOCUMENT (GREETING, MESSAGE)>     <!ELEMENT GREETING (#PCDATA)>     <!ELEMENT MESSAGE (#PCDATA)> ]> <DOCUMENT>     <GREETING>         Hello From XML  <MESSAGE>   </GREETING>  Welcome to the wild and woolly world of XML.     </MESSAGE> </DOCUMENT> 

You can see the results in Figure 1-12 in Chapter 1; as you see there, the validator is indicating that there is a problem with these two tags. In general, then, you can use a validator to check your document. Validators can help a great deal, as you're writing long and difficult XML documents, because you can often check them at each development stage.

Having gotten the <!DOCTYPE> element in place, we're ready to start creating the DTD, starting with the <!ELEMENT> element.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net