All XML documents must be well-formed, but it is not required that a document be valid unless the XML parser is "validating", in which case the document is also checked for conformance with its associated schema.
DTD-validating parsers are most common, but some support W3C XML Schema or RELAX NG as well.
Documents are only considered valid if they satisfy the requirements of the schema with which they have been associated.
In practice, however, many schema validators are integrated with an XML parser.There are several different languages available for specifying an XML schema. The primary purpose of a schema language is to specify what the structure of an XML document can be.This means which elements can reside in which other elements, which attributes are and are not legal to have on a particular element, and so forth.A schema is analogous to a grammar for a language; a schema defines what the vocabulary for the language may be and what a valid "sentence" is.An XML schema is a description of a type of XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic syntactical constraints imposed by XML itself.
These constraints are generally expressed using some combination of grammatical rules governing the order of elements, Boolean predicates that the content must satisfy, data types governing the content of elements and attributes, and more specialized rules such as uniqueness and referential integrity constraints.There are languages developed specifically to express XML schemas.The Document Type Definition (DTD) language, which is native to the XML specification, is a schema language that is of relatively limited capability, but that also has other uses in XML aside from the expression of schemas.Two more expressive XML schema languages in widespread use are XML Schema (with a capital S) and RELAX NG.The mechanism for associating an XML document with a schema varies according to the schema language.The association may be achieved via markup within the XML document itself, or via some external means.