Re: Validating XML

From: Date: Tue, 27 Apr 2004 00:37:57 +0000
Subject: Re: Validating XML
References: 1  Groups: php.general php.xml.dev 
Request: Send a blank email to php-general+get-184706@lists.php.net to get a copy of this message
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 -- adam@trachtenberg.com author of o'reilly's php cookbook avoid the holiday rush, buy your copy today!

« previous php.general (#184706) next »