|Lesson 2||Beyond well-formedness|
|Objective||Describe a valid XML Document|
Describe valid XML Document
A document is only an XML document if it is well-formed.
But, as Robert Glushko has stated, "Well-formed XML is a black hole."
Anyone can create structure.
The challenge is to create a meaningful structure and apply it consistently.
To share information across documents, you should find or create a Document Type Definition, or DTD, to define which elements will be used and how.
As an example, Oracle has defined a specification for creating Java enterprise components.
Using the Enterprise Java Beans specification, a developer can declaratively, as opposed to programmatically, specify infrastructure services for these components.
Infrastructure services include security, transactions, and directory services.
A developer uses XML to declare these services.
The DTD for creating these XML documents has been created by Sun Microsystems.
As a result, when developers create these XML documents, they are assured that other applications will be able to reference and validate the XML documents.
The following Slide Show describes the role of the DTD.
- A DTD specifies the structure and syntax of XML elements. By referring to a DTD, you can delineate correct and incorrect usage of XML elements.
- Is it appropriate for the BOOK element to contain the AUTHOR element, or should the AUTHOR element contain the BOOK element?
- Some of these decisions will be yours, especially if you are creating standards within an organization or industry.
- XML documents that conform to a DTD are considered valid. XML documents that do not conform to a DTD are not valid documents.
DTD Syntax Structure
Well formed and Calid
When creating XML documents, you should strive to create documents that are both well-formed and valid.
These characteristics will give your documents the greatest possible range of options for interoperability with other applications.
Although XML allows you to invent as many different elements and attributes as you need, these elements and attributes, as well as their contents and the documents that contain them, must all follow certain rules in order to be well-formed. If a document is not well-formed, any attempts to read it or render it will fail. The XML specification strictly prohibits XML parsers from trying to fix and understand malformed documents. All a parser can do is signal the error and is not allowed to fix the error. It cannot make a best-faith effort to render what the author intended. It cannot ignore the offending malformed markup. All it can do is report the error and exit.
The objective here is to avoid the bug-for-bug compatibility wars that have hindered HTML and that have made writing HTML parsers and renderers so difficult. Because web browsers allow malformed HTML, web page designers do not make the extra effort to ensure that their HTML is correct.
In fact, they even rely on bugs in individual browsers to achieve special effects. To properly display the huge installed base of HTML pages, every new web browser must support every nuance, every quirk of all the browsers that have come before. The marketplace would ignore any browser that strictly adhered to the HTML standard. It is to avoid this sorry state that XML processors are explicitly required to only accept well-formed XML.
In the next lesson, you a simple DTD will be examined.