php - 带有实体引用的 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 and & check</section-heading>
<section>
<section-heading>Another sub section heading with and & check</section-heading>
</section>
</section>
xml 中有一个实体文件的引用,该文件isonum.ent
位于 xml 文件所在的同一路径中。
实体文件有定义
<!ENTITY rdquo "”" ><!--=double quotation mark, right-->
<!ENTITY nbsp " " ><!--=no break (required) space-->
<!ENTITY shy "­" ><!--=soft hyphen-->
我用于验证的 php 代码如下
$proc = new Saxon\SaxonProcessor(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 提供的示例,但可以确定解决方案。
我怎么能提到架构验证器在哪里寻找实体文件。并且也可以一次得到所有错误,因为在这种情况下,验证只返回一个
问题,因为文件中有两个
's。
解决方案
结果证明这是一个简单的用户错误。DTD 声明了一个参数实体,但没有引用它,因此参数实体的内容不会成为 DTD 的一部分。它需要写成:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section [
<!ENTITY % ent1 SYSTEM "isonum.ent">
%ent1;
]>
推荐阅读
- android - 尝试在firebase上添加新孩子时android应用程序冻结
- java - 如何在build.gradle文件中定义一个方法,可以从一个目录编译java文件并复制一些文件
- node.js - 在 Codeceptjs 中显示响应 - API
- reactjs - 服务器端使用反应的动态元标记
- jasper-reports - TIBCO 检查集合是否为空 jasper 报告数据集查询
- angular - Ionic 生产版本中的“未找到模块”
- ios - 使用 NotificationCenter 的加载器
- javascript - 在打开的窗口中从 angularJS 捕获 url
- php - 如何选择特定列的最小时间和最大时间?
- angular - 角度 4 防止在部分路径上显示组件