HTML and CSS Reference
In-Depth Information
In XHTML, this code would be rewritten as follows:
A minimized attribute
can be updated to
XHTML by using the
name of the attribute as
the attribute's value.
Failure to make this change would cause the XHTML document to be rejected as not
well formed. Note that in HTML5, either form is accepted: You can write such an attri-
bute either with the attribute value or without.
Creating Valid XHTML Documents
In addition to being tested for well-formedness, XML documents also can be checked
to see if they are valid. A valid document is a well-formed document that also contains
only those elements, attributes, and other features that have been defined for the XML
vocabulary that it uses. For example, if the code
were entered into an XHTML file, the code would be considered well formed because it
complies with the syntax rules of XML—but it would not constitute valid XHTML code
because XHTML does not have a mainhead element. To specify the correct content and
structure for a document, the developers of an XML-based language can create a collec-
tion of rules called the document type definition or DtD . As shown in Figure 9-7, an
XML parser tests the content of a document against the rules in the DTD. If the document
does not conform to those rules, the parser rejects the document as not valid.
figure 9-7
testing for validity
XML parser
the parser checks for syntax
errors in the XML document
and compares the document
content with the rules specified
in the DTD
if the document is well formed,
and valid, it is passed by the
parser and displayed by the
browser or other XML application
the document author writes the
code of the XML document
For example, an XML document for a business might contain elements that store the
name of each product in inventory. The DTD for that document could require that each
product name element be accompanied by an id attribute value, and that no products
share the same name or id. An XML parser would reject any XML document that didn't
satisfy those rules, even if the document was well formed. In this way, XML differs from
HTML, which does not include a mechanism to force Web page authors to adhere to
rules for syntax and content.
Search WWH ::

Custom Search