Forum Moderators: open

Message Too Old, No Replies

PHP/XML question - which model to use?

expat or dom and why

         

sneaks

6:37 pm on Sep 4, 2005 (gmt 0)

10+ Year Member



i come from a design background but after playing around with simpleXml and its extended class i felt i wanted to write something more customized for my use. Using the DOM, which I chose for a few reasons, after going through some tutorials and researching, i felt it seemed to be appropriate for me and my level of 'self-taught' php programming. Furthermore, I had used DOM specs in javascript programming and have an okay understanding of it, as well as being a W3C spec which seems to fall in line with my goals or intentions.

I'm really curious why people choose the route they have for processing XML with PHP. I am aware of the processor load and processing times that are associated with each method, but would appreciate any light shed on this subject that elaborates or goes further than that.

What kind of projects do you use either for? I am working on a shell for a blogging, forum, or site news type application that uses xml instead of a database. previously, i have designed a blog that uses flat text files.

take care
jonathan

saurab

7:20 pm on Sep 4, 2005 (gmt 0)

10+ Year Member



Hi,
the choice of a tree-based parser is appropriate for those cases wherein the xml doc is small in size, and when you also need to capture data from nearly about all the tags.. because then it makes sense to make a tree out of the whole doc. for such cases DOM is a good choice .. example: config files .. you need typically all the data from config files.

an event based parser like expat is appropriate when you just need data gleaned from certain specific tags which happen to be a relatively small subset of the total number of tags present in an xml doc. in such cases it makes lesser sense to create a tree out of the whole doc when you only need data from a small number of tags.....
also, event based parsers have small memory footprints .. so they are typically well suited if your web app is a part of a high traffic website....

coding-wise, programmers love dom because the syntax is so elegant and the resultant xml tree makes it so easy to get to the child nodes or the parent nodes corresponding to any given node.

ultimately, it depends on your app.