PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_DTD » Manual

Parses DTD files and does DTD validation of XML documents.

Introduction

Introduction – Introduction to XML_DTD

Introduction to XML_DTD

XML_DTD is able to parse a document type definition (DTD) file and validate XML documents according to this DTD. A DTD is the grammar of an XML application, it consist of rules that declare how tags have to be nested and which attributes may be used in the tags.

If you want to learn how to create a DTD, you should take a look at the W3C.

XML_DTD consits of three parts:

If you validate an XML_Document using XML_DTD_XmlValidator, it will automatically parse the DTD file and create an XML_DTD_Tree from it.

Example

Example – Example usage of XML_DTD

Example usage of XML_DTD

You can validate a XML file against a DTD using isValid() like in the example below:

<?php

require_once 'XML/DTD/XmlValidator.php';

$dtd_file = realpath('myfile.dtd');
$xml_file = realpath('myfile.xml');

$validator = new XML_DTD_XmlValidator();
if (!$validator->isValid($dtd_file, $xml_file)) {
    die($validator->getMessage());
}

?>

isValid() will return true when the XML document validates and false otherwise.

This is pretty much the most common usage of XML_DTD and all you need to know to get started.