How can I set text value of SimpleXmlElement without using its parent? How can I set text value of SimpleXmlElement without using its parent? php php

How can I set text value of SimpleXmlElement without using its parent?


You can do with a SimpleXMLElement self-reference:

$firstC->{0} = "Victory!!"; // hackity, hack, hack!//  -or-$firstC[0]   = "Victory!!";

found after looking at

var_dump((array) reset($xml->xpath("(//c)[3]")))

This also works with unset operations as outlined in an answer to:


The real answer is: you kind of can't.

On the other hand you can use DOM for it, e.g.

dom_import_simplexml($node)->nodeValue = 'foo';