XML Validation

XML is a process by which an XML document is validated. An XML document is said to be valid if its content match with the elements, attributes, and associated Document Type Declaration (DTD), and if the document compiles with the constraints expressed in it. Validation is handle in two ways by XML parser.

  • Well-formed XML document.
  • Valid XML document.

Well-formed XML Document

  • Non DTD XML files must use predefined character entities for amp (&), apos (single quote), gt (>), lt (<), quot (double quote).
  • It must follow the ordering of the tag. i.e., inner tag must be closed before closing the outer tag.
  • Each of the opening tags must closing tag or it must be self-ending tag. (<title>?</title> or <title/>).
  • It has only one attribute in start tag, which needs to be quoted.
Example In above example it defines the type of document. (In above example the document type is element type).
  • It include the root element named as address.
  • The child element name, company, and phone is enclosed in its self-explanatory tag.

Valid XML document.

If an XML document is well formed and has an associated Document Type Declaration (DTD), then it is said to be a valid XML document.