带有实体引用的Saxon php-xml模式验证



我正在使用saxon c api EE版本开发一个php应用程序,该应用程序需要根据xsd模式验证xml文件。

当我进行验证时,我得到了以下错误。

org.xml.sax.SAXParseException; systemId: file:**path**/temp.xml; lineNumber: 6; columnNumber: 48; The entity "nbsp" was referenced, but not declared

我的xml文件内容是

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section [
<!ENTITY % ent1 SYSTEM "isonum.ent">
]>
<section>
<section-heading>This is a test Heading &nbsp; and &amp; check</section-heading>
<section>
<section-heading>Another sub section heading with &nbsp; and &amp; check</section-heading>

</section>
</section>

在xml中有一个实体文件isonum.ent的引用,该文件位于与xml文件所在的.相同的路径中

实体文件具有的定义

<!ENTITY rdquo  "&#x201D;" ><!--=double quotation mark, right-->
<!ENTITY nbsp   "&#160;" ><!--=no break (required) space-->
<!ENTITY shy    "&#173;" ><!--=soft hyphen-->

我的验证php代码在下面

$proc = new SaxonSaxonProcessor(true);
$proc->setConfigurationProperty("xsdversion", "1.1");
$proc->setConfigurationProperty("http://saxon.sf.net/feature/validationWarnings", "true");
$proc->setConfigurationProperty("http://saxon.sf.net/feature/multipleSchemaImports", "on");
$val = $proc->newSchemaValidator();
$val->registerSchemaFromFile($xsd_path);
$val->setProperty("report-node", "true");    
$val->setProperty("verbose", "true");
$val->validate($xml_path);

我参考了https://www.saxonica.com/saxon-c/documentation/index.html以及随库提供的示例下载zip,但可以确定解决方案。。

我怎么能提到架构验证器在哪里查找实体文件呢。同时也可以同时获得所有错误,因为在这种情况下,验证只返回一个&nbsp;问题,因为文件中有两个&nbsp;

这是一个简单的用户错误。DTD声明了一个参数实体,但没有引用它,因此参数实体的内容不会成为DTD的一部分。它需要写:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section [
<!ENTITY % ent1 SYSTEM "isonum.ent">
%ent1;
]>

最新更新