1. Computing

Discuss in my forum

XML Parsers - Validating Vs. Non-Validating

Types of XML Parsers

By

An XML parser is a tool to validate your code to ensure it is well-formed. Even through XML is simplistic, it does need to have proper syntax and form. A parser looks at your code and highlights lines that may cause problems. XML parsers are available in two flavors, non-validating and validating. It is important to know the difference between these two styles before selecting a parser.

What is Well-formed?

Well-formed means you dotted all your i’s and crossed all your t’s when writing the XML document. Valid XML requires a declaration statement, root element and closing tags. The elements must be nested correctly.

Poorly Formed XML

<catalog>
<bike>
  <24-inch></24-inch>
<bike>
  <26-inch></26-inch>
</bike>
</bike>

This is not well-formed XML. It lacks a declaration statement and proper nesting. The declaration statement is how the browser knows that you are creating code in the XML language. This sample does have a root element and closing tags, however, the closing tags for <bike> are improperly nested. One element does not close before beginning the next one. The root element is missing a closing tag.

<?xml version= "1.0"?>
<catalog>
<bike>
    <24-inch></24-inch>
</bike>
<bike>
  <26-inch></26-inch>
</bike>
</catalog>

If you ran the first sample through a parser, you would be alerted to the syntax problems with the code.

Non-Validating Parser

A non-validating parser only checks for structure problems with the XML code. This tool will suffice when there is no document type definition (DTD) or schema. The non-validating parser does not compare validation rules you create to the XML code. It does not care about data types or any unique processing instructions. Non-validating parsers only look at the established syntax rules for XML.

Validating Parser

Validating XML parsers looks for validation rules you establish in a DTD or schema. A validating parser does everything a non-validating tool does, but also looks for internal or external instructions to verify that the code matches unique validation rules you design.

  1. About.com
  2. Computing
  3. Web Design / HTML
  4. XML
  5. Parsers
  6. Validating or Non-Validating XML Parsers

©2014 About.com. All rights reserved.