Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alternatives to simpleXML for parsing xml files with PHP

Tags:

php

xml

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.

like image 684
choise Avatar asked Nov 06 '22 13:11

choise


2 Answers

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.

like image 185
Josh Davis Avatar answered Nov 11 '22 09:11

Josh Davis


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.

like image 34
Artefacto Avatar answered Nov 11 '22 11:11

Artefacto