Re: Further SimpleXML suggestions

From: Date: Mon, 30 Jul 2007 13:57:28 +0000
Subject: Re: Further SimpleXML suggestions
References: 1  Groups: php.xml.dev 
Request: Send a blank email to php-xml-dev+get-602@lists.php.net to get a copy of this message
Ben Schmidt wrote:
- 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! It does. Try recent version of PHP.
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. The above are more complex operations and can be done using DOM - this is why we have the interoperability between the extensions.
- A setName method should complement the getName method. XML node names are read only.
- Some way to declare namespace prefixes would be desirable. setDocNamespaces to complement getDocNamespaces, perhaps. Have no idea what you mean by this. getDocNamespaces simply retrieves all xnamespaces declared within the document.
- 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! Whitespace is usually significant so we cant magically add anything to a document.
As to your last question about node value: foreach ($sxe->node AS $node) { $node[0] = "b"; } changes the value for each node to "b". Works at least in recent PHP release. Rob

« previous php.xml.dev (#602) next »