Further SimpleXML suggestions

[email protected] (Ben Schmidt) Mon, 23 Jul 2007 14:51:50 +1000
Newsgroups php.xml.dev
Message-ID <[email protected]>
Hi, Rob,

Thanks heaps for all the time you have given to helping me with my 
questions and suggestions.

Here are a few more, if you'd be so good as to help me with them (or 
anyone else on the list, I suppose):

IMPORTANT ONE:

- It would be nice if $sxe->subelem[]=$value worked. At the moment it 
gives a fatal error (!) when you try to do this; it seems to assume you 
are trying to set an attribute, which is clearly not the case--empty 
brackets imply numeric indices, and an unnamed attribute is nonsense, 
and any XML programmer would know that!

LESS IMPORTANT ONES: a subclass could probably easily be made to do 
these via DOM. However, I reckon these would be useful additions to 
SimpleXML proper, as they bring its manipulaion abilities up to par with 
its access/reading abilities, which I think is desirable.

- It would be nice to be able to add an element in a particular location 
among a group of similar elements (as SimpleXML can enumerate in order 
and access via numeric index). An extra parameter to addChild to add the 
child before another passed node would do. Or some kind of addSibling 
method(s).

- Being able to add a 'subtree' rather than just a simple element would 
be good. You could overload the addChild method, or provide another.

- A setName method should complement the getName method.

- Some way to declare namespace prefixes would be desirable. 
setDocNamespaces to complement getDocNamespaces, perhaps.

- This idea is pretty 'out there', but I think worthy of consideration. 
It would be kinda cool if when adding elements, SimpleXML also added 
'padding' (mostly newlines, but potentially indentation or such too, if 
not too difficult). Since SimpleXML can't operate with mixed 
text/elements, it would be very sensible for it to add such text to keep 
the resulting XML documents looking...well...simple, and it would have 
no effect on how SimpleXML would interpret the document!

What do you reckon? I think these alterations (and the namespace-related 
ones I mentioned in my other email) would pretty much remove all 
SimpleXML's deficiencies from my point of view, and actually make it 
comprehensive.

Smiles,

Ben.



Send instant messages to your online friends http://au.messenger.yahoo.com