Well-formed and valid XML documents May 16, 2008Posted by fofo in XML.
Let’s start by saying this:
If an XML document is valid then by default it is well-formed. Unfortunately the reverse is not always true. Well-formed XML documents do not necessarily have to be valid.
According to XML specification we must follow certain rules to create XML documents. Some of them are
- having exactly one root element
- close all opening tags
- using single/double quotes for attribute values
If an XML document abides by these rules, it is a well-formed XML document.
DTD is primarily used for the expression of a schema via a set of declarations that conform to a particular markup syntax. It describes the structure and content of a document, in terms of constraints on the structure of that document. In DTD we find information such as:
- the parent-child relationship details
- attribute lists
- data type information
- value restrictions
If a document is well formed and also follows the rules in its associated DTD, it is a valid XML document.