Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development

  • Print
  • + Share This

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 (http://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.

  • 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 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-11Figure 1-11 Using an XML validator.

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

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

XML validators give you a powerful way of checking your XML documents—and 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 problem—they'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.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.