class DOM_Object_1 { private $DOM; public $DOM_Object_2; public function __construct( \DOMDocument $SLDDOM ) { $this->DOM = $SLDDOM; } public function __clone() { $this->DOM_Object_2 = clone $this->DOM_Object_2; } public function getDOMNode() { $fragment = $this->DOM->createDocumentFragment(); $node = $fragment->appendChild( $this->DOM->createElement( "Knoten_1" ) ); $node->appendChild( ( $this->DOM->createTextNode( "Textinhalt 1" )) ) ; if( isset( $this->DOM_Object_2 ) ) { $font = $node->appendChild( $this->DOM->createElement( "DOM_Object_2" ) ); $font->appendChild( $this->DOM_Object_2 ); } return $fragment; } } class DOM_Object_2 { private $DOM; public function __construct(\DOMDocument $SLDDOM) { $this->DOM = $SLDDOM; } public function getDOMNode() { $fragment = $this->DOM->createDocumentFragment(); $node = $fragment->appendChild($this->DOM->createElement( "Knoten_2" ) ); $node->appendChild(($this->DOM->createTextNode( "Textinhalt 2" ) ) ); return $fragment; } } $DOM = new \DOMDocument; $DOM->preserveWhiteSpace = false; $DOM->formatOutput = true; $root = $DOM->appendChild( $DOM->createElement( 'root' ) ); $DOM_Object_1 = new DOM_Object_1( $DOM ); $DOM_Object_2 = new DOM_Object_2( $DOM ); $DOM_Object_1->DOM_Object_2 = $DOM_Object_2->getDOMNode(); $root->appendChild( $DOM_Object_1->getDOMNode() ); echo $DOM->saveXML();