22

xsd に対して xml ファイルを検証する方法は? domdocument::schemaValidate() がありますが、エラーの場所はわかりません。そのためのクラスはありますか?そのパーサーをゼロから作成する価値はありますか? それとも車輪の再発明なのか、

4

3 に答える 3

26

このコードはビジネスを行います:

$xml= new DOMDocument();
$xml->loadXML(<A string goes here containing the XML data>, LIBXML_NOBLANKS); // Or load if filename required
if (!$xml->schemaValidate(<file name for the XSD file>)) // Or schemaValidateSource if string used.
{
   // You have an error in the XML file
}

エラーを取得するには、 http://php.net/manual/en/domdocument.schemavalidate.phpのコードを参照してください。

いえ

ジャスティン redwiredesign ドットコム 2006 年 11 月 8 日 03:32 投稿。

于 2012-07-25T13:12:33.487 に答える