Having problems with XMLDocument

From: Date: Thu, 27 Mar 2008 18:59:18 +0000
Subject: Having problems with XMLDocument
Groups: php.general 
Request: Send a blank email to php-general+get-272184@lists.php.net to get a copy of this message
What is wrong with the following code? It's throwing a DOMException when I try to set the id attribute for the $lvl1Node but I can't see why... $doc = new DOMDocument('1.0', 'UTF-8'); $root = $doc->appendChild( $doc->createElement( 'root' )); for( $a = 0; $a <= 3; $a++ ) { $lvl_1_id = 'level_1_' . $a; $lvl1Node = $root->appendChild( $doc->createElement( 'child', $lvl_1_id )); $lvl1Node->setIdAttribute( 'id', $lvl_1_id ); } for( $b = 0; $b <= 3; $b++ ) { $lvl_1_id = 'level_1_' . $b; $lvl_2_id = 'level_2_' . $b; $oElTmp = $doc->getElementById( $lvl_1_id ); if( $oElTmp ) { $lvl2Node = $oElTmp->appendChild( $doc->createElement( 'child', $lvl_2_id )); $lvl2Node->setIdAttribute( 'id', $lvl_2_id ); } else { echo 'Could not find element with id [' . $lvl_1_id . ']<br>'; } } echo '<pre>' . htmlentities( $doc->saveXML()) . '</pre>'; Any pointers would be greatly appreciated. thnx, Chris

« previous php.general (#272184) next »