DOM or SimpleXML

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

DOM or SimpleXML

Post by kendall »

Hey,

I'm a bit undecisive....

I want to use XML to store 'simple data' for feeding to a class. I have been looking through simple xml and seems that its is the preferred choice however I i note that the CDATA issue and this is going to have a big draw back for my development.

What is the better of the two php methods to use? Which function is more likely to be installed on hosting packages? What has been the work around for the CDATA issue with simple xml?
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: DOM or SimpleXML

Post by alex.barylski »

SimpleXML if you need basic manipulation and mostly read only, DOM if you need more control.

SimpleXML shouldn't have an issue with CDATA although I have encountered a few bugs which were annoying. If I recall it was nested UL produced weird results...I can't remember though.

SimpleXML is nice because its stored as an PHP array. DOM requires you to use the DOM methods and when your print_r to see your DOM you don't actually see anything because it uses an internal tree I assume anyways.

I would start with SimpleXML and move into DOM if you need it...much easier to get started with
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: DOM or SimpleXML

Post by Kieran Huggins »

As someone who tried to love XML and failed, may I suggest a different format altogether?

Serialized data works nicely, as does JSON encoded data. There are also a few well understood registry patterns if you want to go the object route.

As a document format XML is just lovely, but as a generic storage container I find it restrictive and ambiguous at best.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Re: DOM or SimpleXML

Post by kendall »

Kieran Huggins,

hate it or love it the underdog is on top....I think xml is lovely i really love its portability usage...yeah parsing can be tricky...but its really light weight...

I have yet to venture into this JSON realm...

thanks for the advise guys...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: DOM or SimpleXML

Post by John Cartwright »

Kieran++
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: DOM or SimpleXML

Post by Maugrim_The_Reaper »

With the right tools, JSON and XML are interchangeable... You could actually make your life easier if you the pick the easiest one to handle and convert back and forth to the other only when required.

That said, I'm an XML animal ;). I prefer to work with it where possible, but there's no escaping the clarity of JSON anymore.
Post Reply