XML technologies / XML / Python & XML / XML basics / Types of conformance

(Excerpt from "Python & XML" by Christopher A. Jones & Fred L. Drake, Jr.)

Like any specification, the XML specification exists primarily to let us check documents and ensure they conform to its rules. If they do, those rules can be used to read, transform, or otherwise use the document. Remember, however, that XML defines two things: the syntax of individual documents and a way to define new languages using XML. We may use only the former, so XML must define conformance in both cases.

If a document uses XML syntax but does not depend on a particular markup language defined using the XML Recommendation, it must be well-formed to conform to XML. This kind of conformance was introduced by XML rather than inherited from SGML. By contrast, a document claiming to use a particular markup language defined in a DTD is valid, if it is well-formed and its elements and character data are arranged according to the rules of that DTD.

The XML specification defines a collection of text as an XML document if it is well-formed according to the specification. The term well-formedness is frequently used in XML and refers to a syntactically acceptable document. For example:

<?xml version="1.0"?>
<book>
    <title>Python und XML</title>
</book>

The preceding document is well-formed. Beyond the XML declaration (described in more detail under The document prolog later on the page “Creating XML documents” ), which states that the document uses XML version 1.0, both the elements book and title are opened and closed so that elements are nested in a strict hierarchy. You cannot open a book and close a magazine.

Well-formedness is necessary but not sufficient for validity, which concerns a document’s conformance to a Document type definition. Having a syntactically acceptable structure is one thing; ensuring that its information is correctly organized and contains every element needed for an application or transaction is another.

The XML specification divides processors into two classes: validating and nonvalidating. Regardless of Validation both must report violations of the specification’s well-formedness requirements; otherwise parsing might be impossible. A validating processor must be able to report DTD violations to the application. It must therefore read the entire DTD and resolve and parse all external Entities (described in Physical structures ) appearing in the DTD itself or the document. Nonvalidating processors, by contrast, need only check the document and its internal DTD subset for well-formedness. Checking well-formedness does not require access to external entities.

Since alternative schema languages appeared, a third form of conformance has been described informally. A document is said to be schema-valid against a particular schema, regardless of the schema language, if it is well-formed and its structure conforms to that schema under the language’s rules. This generalizes the XML Recommendation’s concept of validity. Every valid document is also schema-valid against the schema defined by its DTD, although it may be invalid against other schemas.

  

 

 

 

back to top