[英]What libraries will parse a DTD using PHP
I need to parse DTDs using PHP and am hoping there's a simple library to help out. 我需要使用PHP解析DTD,并希望有一个简单的库可以提供帮助。 Each DTD has numerous <!ENTITY...
and <!-- Comment...
elements, which I need to act upon. 每个DTD都有许多<!ENTITY...
和<!-- Comment...
元素,我需要对其进行操作。
Note that I do not need to validate anything against these DTDs, simply parse them as data files themselves. 请注意,我并不需要验证对这些DTD什么,只是它们解析为数据文件本身。
A few options I've looked at: 我看过几个选项:
James Clarke's SD , which is an option of last resort, but I'd like to avoid the complexity of building/installing/configuring code external to PHP. James Clarke的SD ,这是最后的选择,但我想避免构建/安装/配置PHP外部代码的复杂性。 I'm not sure it's even possible in my situation. 在我的情况下,我不确定它是否可能。
PEAR has an XML_DTD_Parser , which requires installing/configuring PEAR and a number of pear modules, which I'm also not sure is possible, and would rather avoid. PEAR有一个XML_DTD_Parser ,它需要安装/配置PEAR和一些梨模块,我也不确定是否可行,宁可避免。 Has anyone used it with success? 有没有人成功使用它? EDIT: I've since learned that XML_DTD_Parser discards comments, so is not a valid option for my needs. 编辑:我已经知道XML_DTD_Parser丢弃注释,因此不是我需要的有效选项。
PHP XML Classes has the class_path_parser, which another site suggested, but it fails to read ENTITY elements. PHP XML类具有class_path_parser,这是另一个站点建议的,但它无法读取ENTITY元素。 It appears to be using PHP's built in XML parsing capabilities, which use EXPAT. 它似乎使用PHP的内置XML解析功能,它使用EXPAT。
PHP's DOMDocument will validate against a DTD , so must be able to read them, though I don't see how to get at the DTD parser directly at first glance. PHP的DOMDocument将针对DTD进行验证 ,因此必须能够读取它们,尽管我没有看到如何直接进入DTD解析器。
None of the standard XML parsers for PHP give access to general entities*, and few give access to comments. PHP的标准XML解析器都不允许访问常规实体*,很少有人可以访问注释。 PHP's built in XML Parser uses Expat , but does not expose the full expat API; PHP的内置XML Parser使用Expat ,但不公开完整的expat API; in particular, a handler for entities cannot be set. 特别是,无法设置实体的处理程序。 There is a PHP bug filed to add this. 提交了一个PHP错误来添加它。
AFAICT, the only way to handle comments and general entities in a DTD parser is to write your own parser; AFAICT,在DTD解析器中处理注释和一般实体的唯一方法是编写自己的解析器; either by hand, or using one of the lexers and parser generators available for php (eg PHP_LexerGenerator and PHP_ParserGenerator among others). 手动,或使用可用于php的词法分析器和解析器生成器之一(例如PHP_LexerGenerator和PHP_ParserGenerator等)。
* PHP's expat wrapper (XML Parser) does give access to notation declarations, which are similar to, but not the same as general entities. * PHP的expat包装器(XML Parser)确实提供了对符号声明的访问,这些声明声明与通用实体类似但不相同。
I don't know useful this will be... 我不知道这会有用......
If I understand what you're looking for, you're looking for a means to extract the and "nodes" from a DTD in order to act on them. 如果我理解你在寻找什么,那么你正在寻找一种方法从DTD中提取和“节点”以便对它们采取行动。 Very interesting. 很有意思。 Here's where my brain went: 这是我的大脑去的地方:
Regardless, I hope some of this helps. 无论如何,我希望其中一些有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.