简体   繁体   中英

alternatives to simpleXML for parsing xml files with PHP

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.

You can use the DOM extension . It has the advantage many people are already familiar with DOM (coming from eg Javascript). Of course, DOM is very painful.

For reading large XML files, the event model (think SAX ) is a necessity. See here .

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM