哪些库将使用PHP解析DTD [英] What libraries will parse a DTD using PHP

查看:106
本文介绍了哪些库将使用PHP解析DTD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用PHP解析DTD,并希望有一个简单库来提供帮助.每个DTD都有许多<!ENTITY...<!-- Comment...元素,我需要对其进行操作.

I need to parse DTDs using PHP and am hoping there's a simple library to help out. Each DTD has numerous <!ENTITY... and <!-- Comment... elements, which I need to act upon.

请注意,我不需要针对这些DTD进行任何验证,只需将它们解析为数据文件本身即可.

Note that I do not need to validate anything against these DTDs, simply parse them as data files themselves.

我看过的一些选项:

詹姆斯·克拉克的SD ,这是不得已的选择,但我想避免构建/安装/配置PHP外部代码的复杂性.我不确定这种情况是否有可能.

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. I'm not sure it's even possible in my situation.

PEAR具有 XML_DTD_Parser ,它需要安装/配置PEAR和许多pear模块,我也不确定是否可以,并且宁愿避免.有没有人成功使用它? 编辑:从那以后,我了解到XML_DTD_Parser会丢弃注释,因此这不是满足我需要的有效选项.

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. Has anyone used it with success? I've since learned that XML_DTD_Parser discards comments, so is not a valid option for my needs.

PHP XML类具有class_path_parser,另一个站点建议使用该类,但是它无法读取ENTITY元素.它似乎正在使用PHP的内置XML解析功能,该功能使用EXPAT.

PHP XML Classes has the class_path_parser, which another site suggested, but it fails to read ENTITY elements. It appears to be using PHP's built in XML parsing capabilities, which use EXPAT.

PHP的 DOMDocument将针对DTD进行验证,因此必须能够读取它们,尽管我乍看之下看不到如何直接使用DTD解析器.

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的标准XML解析器都没有访问 general 实体*的权限,很少有访问注释的权限. PHP内置 XML解析器使用 PHP错误来添加.

None of the standard XML parsers for PHP give access to general entities*, and few give access to comments. PHP's built in XML Parser uses Expat, but does not expose the full expat API; in particular, a handler for entities cannot be set. There is a PHP bug filed to add this.

AFAICT,在DTD解析器中处理注释和一般实体的唯一方法是编写自己的解析器;可以手动操作,也可以使用可用于php的词法分析器和解析器生成器之一(例如 PHP_LexerGenerator PHP_ParserGenerator 等.

AFAICT, the only way to handle comments and general entities in a DTD parser is to write your own parser; either by hand, or using one of the lexers and parser generators available for php (e.g. PHP_LexerGenerator and PHP_ParserGenerator among others).

*  PHP的expat包装器(XML Parser)确实提供了对符号声明的访问,这些符号声明与通用实体相似,但不相同.

* PHP's expat wrapper (XML Parser) does give access to notation declarations, which are similar to, but not the same as general entities.

这篇关于哪些库将使用PHP解析DTD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆