tags:

views:

34

answers:

3

Hello, i need to generate XML structures on the fly using PHP. I've seen many different ways and libraries, but i would like to know which is the most efficient.

In general i have arrays and its content has to be returned as XML structure.

Thanks in advance.

Greetings ! c.

A: 

You can use this Array2XML class.

Sarfraz
Array2XML is usually much (much!) slower and more CPU intensive then SimpleXML or XMLWriter. I do not have experience with the mentioned class, but previous experiences with other code made me very wary of such design-patters.
berkes
@berkes: Agreed i have proposed this because it is easier for the noobs :) Although decision is there with OP which one he chooses. We have now suggested him both ways :)
Sarfraz
+2  A: 

Most cpu/cycle efficient: probably if you build strings by hand. Most developer/time/clarity efficient: probably SimpleXML.

Wrikken
That's subjective. Personally, I find SimpleXml a pain to use compared to what DOM gives me.
Gordon
Depends, when having to use namespaces, attributes or validation DOM would have my preference indeed. For just plain unchecked tag/value scenarios SimpleXML is in my opinion a lot less verbose,more to-the-point more easily readable, and I'll try some benchmarks, I suspect it's faster. It is however subjective indeed, I'm defending my opinion here, not facts :)
Wrikken
I admit I'm biased against SimpleXml. To me the Simple in SimpleXml means *lack of functionality*, not *simplicity of use*. I find the quirky namespace support, implicit interface and lack of verbosity particularly annoying. DOM just offers so much more control over the nodes - but I understand that not everyone needs/wants it :)
Gordon