【发布时间】:2011-10-13 04:09:26
【问题描述】:
我正在使用 PHP xmlreader 来验证和解析 xml 数据。此 xml 通过 XMLReader::setSchema 函数使用来自本地文件的一些 xsd 模式和通过 xsd:import/include 来自 http:// 的远程 xsd 模式进行验证。一切工作正常,但每次调用时它都会从网络获取 xsd 模式并从磁盘读取。
所以我的问题是:
有没有一种方法可以在本地 RAM 中缓存远程 xsd 架构? 对于本地模式文件,我认为Linux中的tmpfs可以正常工作,但是还有另一种缓存本地xsd模式文件的方法吗?
解决方案
感谢 VolkerK 指出 xmlcatalog 系统。它适用于 libxml/php xmlreader。在 Linux 中,只需编辑文件 /etc/xml/catalog(当您在 Fedora 时它来自 xml-common)添加一些条目,例如(例如):
<rewriteURI uriStartString="http://schemas.xmlsoap.org/soap/envelope/" rewritePrefix="/etc/xml/SOAP-Envolope.xsd"/>
<rewriteURI uriStartString="http://schemas.xmlsoap.org/soap/encoding/" rewritePrefix="/etc/xml/SOAP-Encoding.xsd"/>
和手动下载模式(例如http://schemas.xmlsoap.org/soap/encoding/ -> /etc/xml/SOAP-Encoding.xsd)然后 php xmlreader 在解析 SOAP 消息时按预期工作。
【问题讨论】:
-
这个问题是“仅”关于
setSchema('localfile') vs setSchema('http://something')还是 xsd:import/include 其他您还想缓存的架构文件? -
当然是xsd:import/include,对于setSchema('http://') 很容易实现我自己的缓存系统。
-
这是添加 xml 目录的虚拟指南: 1. 创建 /etc/catalog。 2.
xmlcatalog --create --noout --add "rewriteURI" "http://schemas.xmlsoap.org/soap/envelope/" \ "file:///etc/xml/soap-envelope-1.1.xsd" \ /etc/xml/catalog3.重启apache。
标签: php caching xsd schema xmlreader