| << 18.2.1- Well-Formed Documents | Chapter18 | 18.2.3- Writing DTDs >> |
Valid Documents
As we mentioned earlier, valid documents are well-formed documents that conform to a DTD. When we read a book, manual or magazine article we rarely notice its structure; if it is well written then the structure will be transparent. Yet, without structure there would be no communication. We may notice headings and paragraphs, but many other aspects pass us by. For one thing this structuring makes the information in the document intelligible, either by us or to an application using it. Furthermore, it means that when a document is parsed, by an application for example, it can be checked for the presence of required portions.
There are many programs, known as parsers, available for XML. Some of these parsers are able to validate a document against its DTD, in which case they are known as validating parsers. If the document does not follow the structure of the DTD the parser will raise an error.
We will come back to look at parsers later in the chapter, when we talk about the Document Object Model.
Assuming that, in the first instance, we have an appropriate and well-planned structure for a type of document, then the resulting document instances should be logically complete with respect to its predefined structure. So, in our book example earlier we had:
- The unique opening and closing tags of <books>
- A <book> element, which encapsulates all information on a specific book
- Followed by a title, in a <title> element
- Then the ISBN in the <ISBN> tags
- Followed by the author, description, and price elements
If we had to exchange a lot of information about books in this format, with different people, then there would be many advantages to writing a DTD (or document type definition). Such a book DTD would lay out the structure of how we expect books following the book DTD to be marked up. While we do not need one to write an XML document, it would mean that anyone following the DTD would be able to write an XML file about books that would be valid according to our DTD. In this manner, we could guarantee that any application using the book information, marked up according to our DTD, could understand the document; it could even check that the document followed the DTD in order to prevent the application showing errors if we passed in the wrong data. You could think of this as being similar to form validation for incoming and outgoing data, to make sure that it conforms to the DTD without the need for writing complex script to check the document.
So, if we had written any applications to process an XML file, created according to our book DTD then, in fact, we would be able to process any files that were valid according to the book DTD. In which case, if Wrox had different members of staff all writing XML documents about the books they could all follow the DTD to make sure that they were valid. Then, should other publishers adopt the same DTD, the bookstores who might make use of our XML files would be able to use the same applications to process the files sent from several different publishers.
| << 18.2.1- Well-Formed Documents | Chapter18 | 18.2.3- Writing DTDs >> |

RSS

