Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php xmlReader vs xmlparser

I know the difference between xmlreader and other tree based parsers like simplexml and dom. But what is the difference between xmlreader and xmlparser? Is there any benefit in using one over another?

I need to parse relatively big xml files, affiliate datafeeds about 100M.

like image 948
neonib Avatar asked Oct 07 '22 21:10

neonib


1 Answers

They utilize two different software architectures - push vs pull.

XMLReader is a "pull parser". You are responsible for creating a big loop and calling the read() function to move the cursor forward. This software architecture tends to be easier to understand intuitively.

XMLParser is an event-based "push parser". You are responsible for registering callback functions that are triggered by events such as start_element, end_element, character_data, start_namespace_decl, etc. When you call xml_parse(), the Expat library will process the entire XML document using your callback functions.

If you don't understand the subtleties between push vs pull architecture, then I recommend that you start with XMLReader because "pull" is simpler to understand and easier to visualize.

like image 52
geofflee Avatar answered Oct 10 '22 02:10

geofflee