Linked by Eugenia Loli on Tue 27th Feb 2007 23:56 UTC, submitted by IdaAshley
General Development This first article of a three-part series introduces PHP5's XML implementation and help those relatively new to using XML with PHP to read, parse, and manipulate, and write a short and uncomplicated XML file using the DOM and SimpleXML in a PHP environment.
Thread beginning with comment 217271
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[3]: Ugh XML
by robinh on Wed 28th Feb 2007 16:49 UTC in reply to "RE[2]: Ugh XML"
robinh
Member since:
2006-12-19

There's no supprise the JSON integrates better in to the PHP language, as it is effectively a cross-platform object persistence syntax. SimpleXML (or any xml binding API for that matter) suffers from the same problem: nested programming language constructs (arrays, hashes, objects etc) cannot represent 'complex' XML. (I'd post a example, but the forum software would swallow it!)

I've heard the argument many times that XML is bloat: and looking at an XML file, you can see what these people are getting at. However, XML tries to be a generic format, so it is inevitable that this will be less succinct than a format designed for a particular data set type. The advantage of using XML is that the same set of APIs can be re-used in many different situations.

Cheers
--Robin
ps. Why is XSLT a disadvantage?

Reply Parent Score: 1

RE[4]: Ugh XML
by stestagg on Wed 28th Feb 2007 18:56 in reply to "RE[3]: Ugh XML"
stestagg Member since:
2006-06-03

cannot represent 'complex' XML.

Yeah. I agree with this, tag attributes can't be mapped directly to PHP objects, but simple workarounds could be used by any library to better integrate with PHP, by taking advantage of XMLs draconian tag and attribute naming restrictions.

However, XML tries to be a generic format

I applaud the morals behind XML and what it sets out to achieve, however it ends up just being more restrictive than something like JSON. By not defining any data-types, representing something common, like an array, becomes very verbose. JSON can represent text (arguably all the XML can do), binary data (without all the <!cdata crap), arrays, hashtables and numbers in a standardised manner. In some ways, json can be as generic as XML, it can also be much more powerful byte-for-byte.


The advantage of using XML is that the same set of APIs can be re-used in many different situations.


Yes this is an advantage, but by using this philisophy, you are restricted by the lowest-common-denominator. Sure, the XML libraries for C have a similar API to those for PHP, but the JSON C++ libs take advantage of the extra features of C++ to provide a more natural interface.

Sorry if I seem a bit agressive, I really don't like XML ;) .

ste.

p.s. try googling xslt considered harmful. And read about 'Formatting Objects'

Reply Parent Score: 2

RE[5]: Ugh XML
by jayson.knight on Thu 1st Mar 2007 06:03 in reply to "RE[4]: Ugh XML"
jayson.knight Member since:
2005-07-06

"By not defining any data-types, representing something common, like an array, becomes very verbose."

It's interesting you should mention that...think about it for a second, why is it difficult for XML to represent something as fundamentally simple as an array? What if (using .Net or Java) it's an array of objects? XML has no notion of something such as an object, much less an array of them. Or a hashtable, which can be a container for pretty much any kind of underlying data structure, most of which are impossible to express in XML without adding some sort of proprietary mess to it.

Expressing arrays of types known in XML (strings, numeric primitives) is easy, and almost all languages can pass around XML docs with arrays of those types (think web services), but this has to be limited to the most basic of types.

This is an area where JSON really has an edge. Remember how long XML took to become mainstream though. JSON is relatively new to the scene, and it'll be up to the language designers to build libraries that support it.

Edited 2007-03-01 06:04

Reply Parent Score: 2

RE[5]: Ugh XML
by robinh on Thu 1st Mar 2007 09:12 in reply to "RE[4]: Ugh XML"
robinh Member since:
2006-12-19

Much as I hate to have to roll out the old adage, XML and JSON are both simply tools. In the same way that you wouldn't want to hammer a nail into a wall with a screwdriver, you probably wouldn't want to replace, say, HTML with a JSON equivalent (just think for a minute how that might work - it wouldn't!).

XML and JSON are both excellent tools in their own right when applied as a sensible solution to a programming problem. What concerns me, is that this current fad of "anti XML fanboy-ism" is leading otherwise excellent programmers to overlook XML for the wrong reasons. It's like a whole bunch of carpenters suddenly banned themselves from even thinking about using a hammer.

Try and be objective about the strengths and weaknesses of XML and JSON and whatever else you come across, and that way you'll not fall in to the trap of using one where the other would be more suitable.

--Robin
p.s. I'm currently working on a project using XSL-FO, XSL, SOAP. Going very well, easy to set up, and about 10,000 times better than a solution programmed from scratch in PHP by a programmer who _used_ to work for my company!

Reply Parent Score: 1