XML Validation
Page Index
Introduction
XML that uses the correct syntax, as given by the World Wide Web Consortium (W3C), is Well-Formed XML. XML that is verified against a DTD or schema is Valid XML.
Well-Formed XML
Well-formed XML follows some general rules. More detailed rules can be found at the W3C's recommended XML specifications.
The general syntax of well-formed XML is discussed in the section XML Syntax. These rules are as follows:
- Your file should contain an XML declaration.
- Your file should have a single root node.
- All elements and child elements should be closed and nested properly.
- All attributes should be enclosed in quotes.
Validating with a DTD
A Document Type Definition (DTD) provides the structure for an XML document by listing the legal elements of an XML document, including which names are to be used for different types of elements, where they may occur, and how they all fit together. A DTD can be declared inline in your XML document, or as an external reference. DTD standards are defined by the W3C. The W3C site provides a comprehensive reference of DTDs. You can find more information on DTDs by using the following tutorials:
- W3School's DTD Tutorial
- XMLFiles' DTD Tutorial
- TheScarms Visual Basic Code Library DTD Tutorial
Validating with a Schema
An XML Schema is an XML-based alternative to DTD. The XML Schema language is also referred to as XML Schema Definition (XSD). Like a DTD, an XML schema describes the structure of an XML document. Schemas use XML syntax and are more powerful and flexible than DTDs. You can find more information on XML Schemas in the following pages:
- W3School's XML Schema Tutorial
- Robin Cover's Schema Pages
Validating with RELAX NG
Many people prefer using the RELAX NG validation framework. Developed within OASIS specifications, RELAX NG integrates XML and non-XML syntax, has unrestricted support for unordered and mixed content, and can be used with a separate datatyping language such as w3c XML schema datatypes.
| Related Links | |
|---|---|
|
About XML XML Alternatives XML Validation ![]() How to Write XML XSL Stylesheets |
|
| User Contributed Notes Validating XML |
+ Add a comment |
| + View comments |


