Tip Two Types of Validation

In XML there are two types of validation. One is checking whether the document is well-formed (see Tip 17-5). The other type of validation requires that you create a Document Type Definition (DTD) or a set of rules (known as schema) to determine the type of elements and attributes an XML document should contain, how these elements and attributes should be named, and the relationship between the elements. The DTD or schema for an XML document is optional. You create either one only if you are planning to validate data. In XML, data validation is accomplished by comparing the document with the

DTD or schema. When you open the XML document in a parser, the parser compares the DTD to the data and raises an error if the data is invalid. This book does not explore the creation and use of DTDs or schemas. What you should remember from this tip is that a valid XML document is not the same as a well-formed XML document. A valid XML document conforms to a structure outlined in the Document Type Definition (DTD) or schema, while well-formed documents follow the basic formatting rules mentioned in Tip 17-5.

0 0

Post a comment