Results 1 to 1 of 1
Mar 31, 2005, 08:36 #1
object data output.. the professional way
I've been toying with a variety of different ways to output data, in addition to my search for a better and decoupled templating system,a nd have been exploring an interesting option.
My idea is similar to the .toString() method found in most java classes, but a toXML method that exports the objects data structure (and it's components) as XML, as a DOMXML object. The idea is, I could do something like this:
$item = new item($_GET["id"]);
$description = $item->toXML();
$pi = $description->create_processing_instruction
$elements = $description->get_elements_by_tagname('item');
I suppose my question is... is this good design? One drawback would seem that every class would need a custom coded toXML() method to generate xml, or one would have to create a decorator object to generate the xml (since one may also export as an array, perhaps for it to be used by another object). The decorator solution does get a bit messy though, and it seems sooner or later you perhaps need to get verbose with how the xml is generated (orjust transform an array into xml, kinda like PEAR::XML_Serializer does).
James Carr, Software Engineer