alternatives to simpleXML for parsing xml files with PHP

不羁的心 提交于 2019-12-07 06:47:47

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/2892313/alternatives-to-simplexml-for-parsing-xml-files-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!