Re: [PHP-XML-DEV] Validating XML
[email protected] (Adam Maccabee Trachtenberg) Mon, 26 Apr 2004 20:37:57 -0400 (EDT)
| Newsgroups | php.general,php.xml.dev |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 26 Apr 2004, Michael wrote:
> I saw that the new simpleXML extension did have a method that
> appeared to validate XML against a schema file, but this method now
> appears to be removed from the current PHP 5 release candidate.
> What other options are available to PHP?
You can validate files in PHP 5 using the DOM extension:
$file = 'foo.xml';
$schema = 'foo.xsd';
$foo = DOMDocument::load($file);
if ($foo->schemaValidate($schema)) {
print "$file is valid.\n";
} else {
print "$file is invalid.\n";
}
This does XML Schema validation, but there's also relaxNGValidate()
for RelaxNG. If your document declares a DTD, then you can call
validate() for a DTD validation.
-adam
--
[email protected]
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!