XML Validator

Validation is a process by which an XML document is validated. An XML document is said to be valid if its content matches with the elements, attributes and other piece of an associated document type declaration(DTD) and if the document complies with the constraints expressed in it. Validation is dealt in two ways by the XML parser. They are:

  • Well-formed XML document

  • Valid XML document

Well-formed XML document

An XML document is said to be well-formed if it adheres to the following rules:

  • NON DTD XML files must use the 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 the outer tag is closed.

  • Opening tags must have a closing tag or have themselves self ending.
    (<title>….</title> or <title/>).

  • Must have only one Attribute in a start tag, and has to be quoted.

  • amp(&), apos(single quote), gt(>), lt(<), quot(double quote) Entities other than these must be declared.

Example

Example of well-formed XML document:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE address
[
   <!ELEMENT address (name,company,phone)>
   <!ELEMENT name (#PCDATA)>
   <!ELEMENT company (#PCDATA)>
   <!ELEMENT phone (#PCDATA)>
]>
<address>
   <name>Tanmay Patil</name>
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</address>

Above example is said to be well-formed as:

  • It defines the type of document. Here document type is element type.

  • It includes a root element named as address.

  • Every child elements are enclosed within the self explanatory tags. Here child elements are name, company and phone.

  • Order of tags is maintained.

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. We will study more about DTD in the XML – DTDs.


anime porn
This entry was posted in   XML.
Bookmark the   permalink.

Admin has written 171 articles