XML Validator

To syntax-check our XML, we use an XML validator.

Well-Formed XML Documents:

A “Well Formed” XML document is the one with the correct syntax.

Syntax rules:

In XML

  • Documents must have a root element.
  • Elements must have a closing tag.
  • Tags are case sensitive.
  • Elements must be properly nested.
  • Attribute values must be quoted.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Sapna</to>
<from>Tom</from>
<heading>Meeting</heading>
<body>Meeting on Monday Morning at 9 AM.</body>
</note>

XML Errors:

An XML application is stopped by errors in XML documents. According to the W3C XML specification, on finding an error, a program should stop processing an XML document, to make sure that the XML software is small, fast, and compatible. HTML documents with errors (like missing end tags) can be displayed by the HTML browsers. But, errors are not allowed with XML.

Valid XML Documents:

A “well-formed” XML document and a “valid” XML document are not same. Along with being well-formed, a “valid” XML document must also conform to a document type definition.

Different document type definitions used with XML are:

  • DTD – The original Document Type Definition
  • XML Schema – An XML-based alternative to DTD

The rules and the legal elements and attributes for an XML document are defined by a document type definition.

Please Share