SCDJWS Study Guide: XML Basic


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

XML Validation

An XML document needs to be valid to be of practical use. An XML valid document obeys the following rules:

  1. The XML document must be well formed. A "Well Formed" XML document is a document that conforms to the XML syntax rules that were described in the previous XML Syntax section.

  2. The XML document must apply to the rules as defined in a XML Schema or Document Type Definition (DTD).

  3. A "Valid" XML document is a "Well Formed" XML document (there is no possibility for typo�s in the tags), which also conforms to the rules defined in its XML schema (there�s no possibility to use a tag that is not defined in the XML schema).

Validity is another important XML concept. A document instance is valid when it parses successfully against its accompanying DTD or XML schema. As mentioned XML does not require the use of a DTD or XML schema, but when a document instance invokes a DTD or schema, then a parser will validate the document instance against it. If it parses successfully to build XML document tree, the document is both well-formed and valid. A document instance can be well-formed but not valid if it has a DTD or XML schema and violates the rules of its DTD or schema. For example, its schema may require an element to be numeric only. If the numeric-only element contains an alpha character, it would be invalid. Parsed without invoking its DTD, it could very likely be well-formed. If a document instance is valid, then it is always well-formed.

The W3C XML specification states that a program should not continue to process an XML document if it finds a validation error. The reason is that XML software should be easy to write, and that all XML documents should be compatible.

Note:

DTDs can be used to describe XML markup languages and to validate XML documents, but they are also limited. DTDs describes how elements and attributes are organized in a markup language, but they fail to address data typing. XML Schema was created to address the limitations of DTDs. This is also the reason that XML Schema is preferred to DTDs in Web Services.



Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |