请确保在调用 ->setRelaxNGSchema() 之前加载数据,否则你将会遇到错误。
<?php
$xml_reader = new XMLReader();
$xml_reader->setRelaxNGSchema($rng_schema);
$xml_reader->xml($xml_data);
?>
上面的代码会生成如下警告:"Warning: XMLReader::setRelaxNGSchemaSource()
[xmlreader.setrelaxngschemasource]: Unable to set schema. This must be
set prior to reading or schema contains errors."
而下面的代码则不会生成警告
<?php
$xml_reader = new XMLReader();
$xml_reader->xml($xml_data); // 或 $xml_reader->xml($xml_file);
$xml_reader->setRelaxNGSchema($rng_schema);
?>
参见 http://bugs.php.net/bug.php?id=46978