您对 PHP 使用什么 XML 解析器? [英] What XML parser do you use for PHP?

查看:26
本文介绍了您对 PHP 使用什么 XML 解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢 XMLReader 类,因为它的简单性和速度.但我喜欢与 xml_parse 相关的函数,因为它可以更好地进行错误恢复.如果 XMLReader 类会针对无效实体引用等问题抛出异常而不是仅仅发出警告,那就太好了.

I like the XMLReader class for it's simplicity and speed. But I like the xml_parse associated functions as it better allows for error recovery. It would be nice if the XMLReader class would throw exceptions for things like invalid entity refs instead of just issuinng a warning.

推荐答案

如果可以,我会避免使用 SimpleXML.尽管通过避免大量丑陋"的代码看起来很诱人,但正如名字所暗示的那样:简单.例如,它不能处理这个:

I'd avoid SimpleXML if you can. Though it looks very tempting by getting to avoid a lot of "ugly" code, it's just what the name suggests: simple. For example, it can't handle this:

<p>
    Here is <strong>a very simple</strong> XML document.
</p>

咬紧牙关,转到 DOM 函数.它的力量远远超过了一点点额外的复杂性.如果您完全熟悉 Javascript 中的 DOM 操作,那么您会对这个库感到宾至如归.

Bite the bullet and go to the DOM Functions. The power of it far outweighs the little bit extra complexity. If you're familiar at all with DOM manipulation in Javascript, you'll feel right at home with this library.

这篇关于您对 PHP 使用什么 XML 解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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