XML Validators

How do you know if your XML document is well formed and valid? One way is to check it with an XML validator, and there are plenty out there to choose from. 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 (http://validator.w3.org/) 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.

  • http://www.xml.com/pub/a/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.

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

  • http://www.stg.brown.edu/service/xmlvalid/ The excellent XML validator 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 a validator at work, take a look at Figure 1-11. There, I'm asking the XML validator from the Scholarly Technology Group to validate the XML document c:\xml\ch01_02.xml, where I've 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> 
Figure 1-11. Using an XML validator.

graphics/01fig11.gif

You can see the results in Figure 1-12; the validator is indicating that there is a problem with these two tags.

Figure 1-12. The results from an XML validator.

graphics/01fig12.gif

XML validators give you a powerful way of checking your XML documentsand that's useful because XML is much stricter about making sure a document is correct than HTML browsers (recall that XML browsers are not supposed to make attempts to fix XML documents if they find a problemthey're just supposed to stop loading the document).

We've gotten a good overview of XML already in this chapter, and in a few pages I'll start taking a look at a number of XML languages that are already developed. However, there are a few more topics that are useful to cover first, especially if you have programmed in HTML and want to know the differences between XML and HTML.



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