PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DOMDocument::xinclude> <DOMDocument::schemaValidateSource
Last updated: Fri, 05 Sep 2008

view this page in

DOMDocument::validate

(No version information available, might be only in CVS)

DOMDocument::validate Validates the document based on its DTD

Description

bool DOMDocument::validate ( void )

Validates the document based on its DTD.

You can also use the validateOnParse property of DOMDocument to make a DTD validation.

Return Values

Returns TRUE on success or FALSE on failure. If the document have no DTD attached, this method will return FALSE.

Examples

Example #1 Example of DTD validation

<?php
$dom 
= new DOMDocument;
$dom->Load('book.xml');
if (
$dom->validate()) {
    echo 
"This document is valid!\n";
}
?>

You can also validate your XML file while loading it:

<?php
$dom 
= new DOMDocument;
$dom->validateOnParse true;
$dom->Load('book.xml');
?>



add a note add a note User Contributed Notes
DOMDocument::validate
darren at viamedia dot co dot za
05-Aug-2008 04:19
If you are loading xml with the intention of validating it against an internal dtd and you have experienced issues with the validation it could be related to missing LIBXML constants.

I found this post by "aidan at php dot net" in root level dom docs and thought it might be more useful here:
As of PHP 5.1, libxml options may be set using constants rather than the use of proprietary DomDocument properties.

DomDocument->resolveExternals is equivilant to setting
LIBXML_DTDLOAD
LIBXML_DTDATTR

DomDocument->validateOnParse is equivilant to setting
LIBXML_DTDLOAD
LIBXML_DTDVALID

PHP 5.1 users are encouraged to use the new constants.

Example:
<?php
$dom
= new DOMDocument;
// Resolve externals
$dom->load($file, LIBXML_DTDLOAD|LIBXML_DTDATTR);
// OR
// Validate against DTD
$dom->load($file, LIBXML_DTDLOAD|LIBXML_DTDVALID);
$dom->validate();
?>
shinkan at gmail dot com
09-Jul-2008 05:40
It doesn't seem to support "Internal DTD Declaration" as described by http://www.w3schools.com/dtd/dtd_intro.asp .

DOMDocument::xinclude> <DOMDocument::schemaValidateSource
Last updated: Fri, 05 Sep 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites