1.7. Testing XML

Quality control is an important feature of XML. If XML is to be a universal language, working the same way everywhere and every time, the standards for data integrity have to be high. Writing an XML document from start to finish without making any mistakes in markup syntax is just about impossible, as any markup error can trip up an XML processor and lead to unpredictable results. Fortunately, there are tools available to test and diagnose problems in your document.

The first level of error checking determines whether a document is well-formed. Documents that fail this test usually have simple problems such as a misspelled tag or missing delimiting character. A well-formedness checker, or parser, is a program that sniffs out such mistakes and tells you in which file and at what line number they occur. When editing an XML document, use a well-formedness checker to make sure you haven't left behind any broken markup; then, if the parser finds errors, go back, fix them, and test again.

Of course, well-formedness checking can't catch mistakes like forgetting the cast list for a play or omitting your name on an essay you've written. Those aren't syntactic mistakes, but rather contextual ones. Consequently, your well-formedness checker will tell you the document is well-formed, and you won't know your mistake until it's too late.

The solution is to use a document model validator, or validating parser. A validating parser goes beyond well-formedness checkers to find ...

Get Learning XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.