# new simplexml functionality

- Thread: https://externals.io/message/22117
- Original archive: https://news-web.php.net/php.internals/22117
- Started by Rob Richards on 2006-03-05T14:29:05+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #22117 — Rob Richards — 2006-03-05T14:29:05+00:00

URL: https://externals.io/message/22117#22117

I would like to propose adding addChild and addAtribute methods to 
simplexml. I know these have been shot down in the past, but with 
Marcus' recent changes to simplexml, they now make sense imo.

SimpleXMLElement::addChild(string qName, string value [,string ns])
SimpleXMLElement::addAttribute(string qName, string value [,string ns])

http://www.ctindustries.net/patches/sxe.diff.txt

Rational:
It is not possible to add elements to a tree, but new namespaced 
elements/attributes cannot (although existing ones can be modified).
With these methods, new attributes and elements can be added that will 
also create namespaces with prefixes in the event the do not exist in 
the document.
This would pretty much eliminate the need to use DOM in most cases for 
those who dont want it or have it and make behavior more consistent. It 
doesn't seem right that some things can be added and other things can't.

The method names I used are abritrary so I would not be against changing 
them.
Same goes The behavior of addAtribute. Right now it allows an attribute 
to be added to an attribute list as long as it does not exist and 
respects the namespacing passed in as parameters rather than the 
namespace scope of the attribute list. For now I left it loose, but am 
not against only allowing attributes to be added to elements.

To the argument that DOM could just be used to provide the 
functionality, the same cause could be made for the getName, 
getNamespaces and  getDocNamespaces methods as well and these new 
functions are much more useful imo.

Rob

---

## #22120 — Marcus Boerger — 2006-03-05T14:32:39+00:00

URL: https://externals.io/message/22117#22120 · In reply to: #22117

Hello Rob,

Sunday, March 5, 2006, 3:29:05 PM, you wrote:

> I would like to propose adding addChild and addAtribute methods to 
> simplexml. I know these have been shot down in the past, but with 
> Marcus' recent changes to simplexml, they now make sense imo.

It is important to note that we shot down those in the past because
we hadn't had the support by the generic handlers either. Just becuase
they weren't working as expected and nobody was willing to do it and
partly becuase we believed it impossible. Though now i fixed all
issues it makes sense. What still stands is that originally - in its
first days - the goal of SimpleXML was to not have any function at all.
But that was before we discoverd that this design does not allow to
handle namespaces at all and leaded to unexpected behavior when SXE
was used ofr documents that contained namespaces.

> SimpleXMLElement::addChild(string qName, string value [,string ns])
> SimpleXMLElement::addAttribute(string qName, string value [,string ns])

> http://www.ctindustries.net/patches/sxe.diff.txt

The patch looks good.

> To the argument that DOM could just be used to provide the
> functionality, the same cause could be made for the getName, 
> getNamespaces and  getDocNamespaces methods as well and these new 
> functions are much more useful imo.

I hate DOM for its endless complexity and very much dislike having
to switch between the two.

Best regards,
 Marcus

---

## #22119 — Rob Richards — 2006-03-05T14:35:54+00:00

URL: https://externals.io/message/22117#22119 · In reply to: #22117

Rob Richards wrote:
>
> Rational:
> It is not possible to add elements to a tree, but new namespaced 
> elements/attributes cannot (although existing ones can be modified).
>
Correction: This should say "It is now possible to add elements ...."

Rob
