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:
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.
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.
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. |