PHP xml阅读器: How to cache xsd schema?

标签 php caching xsd schema xmlreader

我正在使用 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 消息时按预期工作。

最佳答案

php 的 xmlreader 使用 libxml并且 libxml 支持 xml catalouges :

What is a catalog? Basically it's a lookup mechanism [...]
It is basically used for 3 things:
[...]
  • providing a local cache mechanism allowing to load the entities associated to public identifiers or remote resources, this is a really important feature for any significant deployment of XML or SGML since it allows to avoid the aleas and delays associated to fetching remote resources.

还没有尝试过,但我想值得一试。

关于PHP xml阅读器: How to cache xsd schema?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6826384/

相关文章:

.net - 需要帮助通过 XML 修改 PrintTickets

php - 表单需要将数据发布到 codeigniter 中的 Controller

c# - 只有一个用于切换开关的 localSetting 被执行 UWP C#

PHP:测试三个变量是否相等

POSIX和PCRE之间的正则表达式语法更改

caching - 处理器的指令在哪里?在 CPU 缓存中还是?

c# - 开始使用 .NET 进行 XSD 验证

jaxb - XSD 允许扩展、兼容性和验证

php - 如何在运行 simplexml_load_file() 之前检查 XML 文件是否良好

javascript - 电子商务 |通过 Ajax 清除购物车