An XML document is valid if along with being well-formed, it conforms to all rules of its DTD. The rules an XML document must obey are:

  • The root element of the document must be the one mentioned in DTD.
  • A document should not contain arbitrary tags, while a well-formed document might contain arbitrary tags.
  • Any tags used in document must be declared in DTD and must be used in the way permitted by DTD.

A validating parser reads DTD and checks the document for the validity. If it finds an error, it reports the same. Most of the browsers do not check for validity of document hence it is good practice to validate the XML document using parser before using. Lot of free validating software are available on web, example: XML for Java, XJParser, SXP ...etc.

Example of a valid XML document

Example of an invalid XML document

 

›› go to examples ››