I have this SimpleXMLElement object with an XML setting similar to the following ...
$xml = <<<EOX <books> <book> <name>ABCD</name> </book> </books> EOX; $sx = new SimpleXMLElement( $xml );
Now I have a class called Book that contains information. about every book. The same class may also spit out book information. in XML format similar to the above (nested block). For instance,
$book = new Book( 'EFGH' ); $book->genXML(); ... will generate <book> <name>EFGH</name> </book>
Now I'm trying to figure out a way by which I can use this generated XML block and add it as a child, so now it looks like ... for example.
// Non-existent member method. For illustration purposes only. $sx->addXMLChild( $book->genXML() ); ...XML tree now looks like: <books> <book> <name>ABCD</name> </book> <book> <name>EFGH</name> </book> </books>
From what documentation I read SimpleXMLElement, addChild () will not do this for you, since it does not support XML data as a tag value.
source share