Reply to Re: XSD

Your name:

Reply:


Posted by Janwillem Borleffs on 12/31/05 19:07

Lόpher Cypher wrote:
> I am wondering if there are any scripts for PHP4 out there to verify
> an XML file against XSD.
>

AFAIK, you can only do this with an external program, e.g. xmllint
(available as part of the libxml2 distribution and as a standalone
executable for Windows; just Google for 'xmllint').

Together with the domxml extension, you could something as followed (not
fully tested):

<?php

class ValidatedDomDocument extends DomDocument {
function schemaValidate($xsd_file) {
if (!file_exists($xsd_file)) {
return false;
}
$xml = $this->dump_mem();
$descriptorspec = array(array("pipe", "r"));
$process = proc_open(
"G:/xmllint/xmllint.exe --schema $xsd_file -",
$descriptorspec,
$pipes
);

if (is_resource($process)) {
fwrite($pipes[0], $xml);
fclose($pipes[0]);
return proc_close($process) == 0;
}
return false;
}
}

$doc = new ValidatedDomDocument('<yourxml />');
print $doc->schemaValidate('yourschema.xsd') ? 'valid' : 'invalid';

?>


HTH;
JW

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация