使用 PHP 解析 xml 文件的 simpleXML 替代方案
我只是想知道是否有 simpleXML 的替代方案来使用 PHP 解析 XML 数据。
例如,如果 simpleXML 模块未加载,或者即使存在比 SimpleXML 性能更好的库/类。
i just want to know if there are any alternatives to simpleXML for parsing XML Data with PHP.
For example if simpleXML module is not loaded or even if there is a lib/class out there that has a better performance then SimpleXML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,作为 PHP 扩展,有大量不同的方法来处理 XML和用户空间库。问题是它们都比 SimpleXML 复杂得多,并且随机访问速度远不如 SimpleXML。
我不确定你问题的目标是什么。这些库/扩展都不共享通用 API,因此如果您希望在 SimpleXML 不可用时进行回退,那么您将不得不重复您的工作。但实际上,几乎没有理由禁用 SimpleXML,因此也没有理由制定这样的应急计划。
Obviously there's a ton of different way to process XML both as PHP extensions and userspace librairies. The problem is they are all much much more complicated than SimpleXML and nowhere as fast for random access.
I'm not sure what's the goal of your question though. None of those libraries/extensions share a common API so if you want a fallback in case SimpleXML isn't available then you'll have to duplicate your efforts. In actuality though, there's virtually no reason to disable SimpleXML so there's no reason to work on such a contingency plan.
您可以使用 DOM 扩展。它的优点是许多人已经熟悉 DOM(来自例如 Javascript)。当然,DOM是很痛苦的。
为了读取大型 XML 文件,事件模型(例如 SAX)是必需的。请参阅此处。
You can use the DOM extension. It has the advantage many people are already familiar with DOM (coming from e.g. Javascript). Of course, DOM is very painful.
For reading large XML files, the event model (think SAX) is a necessity. See here.
好吧,有 XML_Parser (请参阅 http://php.net/manual/en/book。 xml.php) 以及 XMLReader / XMLWriter ( http:// www.php.net/manual/en/book.xmlreader.php / http://www.php.net/manual/en/book.xmlwriter.php)。 SimpleXML 默认编译成 php(至少从 5.x 开始)。我无法告诉您太多有关 XMLReader/XMLWriter 或 XML_Parser 的性能,因为我通常坚持使用 SimpleXML。
干杯,
法比安
Well there is XML_Parser (see http://php.net/manual/en/book.xml.php) aswell as XMLReader / XMLWriter ( http://www.php.net/manual/en/book.xmlreader.php / http://www.php.net/manual/en/book.xmlwriter.php ). SimpleXML is compiled into php per default (at least since 5.x). I can't tell you much about performance of XMLReader/XMLWriter or XML_Parser as I usually stick to SimpleXML.
Cheers,
Fabian