Edit report at https://bugs.php.net/bug.php?id=64440&edit=1
ID: 64440 Updated by: sala...@php.net Reported by: matteosistisette at gmail dot com Summary: SimpleXMLElement needs a way to add text content to a node -Status: Open +Status: Feedback -Type: Bug +Type: Feature/Change Request Package: SimpleXML related Operating System: all PHP Version: Irrelevant Block user comment: N Private report: N New Comment: What's wrong with $element[0] = "someText" ? It is also not very often that one wishes to edit the documentElement's text content. When editing sub-elements the following can be used when there is only one matching "<child>": $element->child = 'some text'; If there are multiple "<child>" elements, then you should specify which one to change: $element->child[2] = 'some text'; There is no requirement to use the "horrible hack" syntax: $element->{0}. Previous Comments: ------------------------------------------------------------------------ [2013-03-16 18:28:46] matteosistisette at gmail dot com Description: ------------ There is currently no way (except for this horrible hack http://stackoverflow.com/questions/3153477/how-can-i-set-text-value-of- simplexmlelement-without-using-its-parent) to add or modify the text content of a xml node with SimpleXMLElement. It needs methods called somethig like addTextContent() or setTextContent() or addTextNode() or whatever. Now please don't tell me this is a feature request. This is a huge design flaw. This is the lack of an obvious, vital feature. Test script: --------------- $xml_a=new SimpleXMLElement("<data/>"); $xml_b=new SimpleXMLElement("<data>someText</data>"); //Now try to modify $xml_a so that it becomes like $xml_b //It's impossible. /* You would need something like: $xml_a->addContent("someText"); or $xml_a->addTextNode("someText"); or $xml_a->setContent("someText"); No way you can accomplish that*/ ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64440&edit=1