我正在根据SVG规范验证SVG文档(我相信它是有效的)。我在PHP中使用XMLReader,并且宁愿坚持使用XMLReader,因为我将在其他地方使用XMLReader;如果有其他基于流的读者会更容易/更好地做到这一点,请告诉我。
好的,这是一些代码:
// Set some values for the purpose of this example
$this->path = '/Users/jon/Development/Personal/Visualised/master/test-assets/import-png.svg';
$xsdPath = '/Users/jon/Development/Personal/Visualised/master/test-assets/xsd/SVG.xsd';
$reader = new XMLReader();
$reader->open($this->path);
$valid = $reader->setSchema($xsdPath);
$reader->close();
好的,我在xsd
文件夹中的XSD文件是:
解析器似乎从第一个导入第二个和第三个XSD - 我希望任何依赖项存储在磁盘上,而不是从互联网上检索。
好的,这是输出:
XMLReader::setSchema(): Element '{http://www.w3.org/2001/XMLSchema}import': Skipping import of schema located at '/Users/jon/Development/Personal/Visualised/master/test-assets/xsd/xml.xsd' for the namespace 'http://www.w3.org/XML/1998/namespace', since this namespace was already imported with the schema located at 'http://www.w3.org/2001/xml.xsd'. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45
Warning: XMLReader::setSchema(): Element '{http://www.w3.org/2001/XMLSchema}attribute': The attribute 'type' is not allowed. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45
Warning: XMLReader::setSchema(): Element '{http://www.w3.org/2001/XMLSchema}attribute': The attribute 'type' is not allowed. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45
Warning: XMLReader::setSchema(): Element '{http://www.w3.org/2001/XMLSchema}attribute': The attribute 'type' is not allowed. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45
Warning: XMLReader::setSchema(): Unable to set schema. This must be set prior to reading or schema contains errors. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45
似乎我可能在某处导入了错误版本的架构 - 我通过网络搜索找到了所有XSD文档。有什么想法吗?
编辑:最后一个错误表明应该在阅读文档之前设置架构。好的,所以我已将代码更改为:
$reader = new XMLReader();
$valid = $reader->setSchema($xsdPath);
$reader->open($this->path);
$reader->close();
- 一些初始警告,但我仍然得到Unable to set schema
一个。