note 25419 added to function.domnode-set-content

From: Date: Mon, 23 Sep 2002 11:21:51 +0000
Subject: note 25419 added to function.domnode-set-content
Groups: php.notes 
Request: Send a blank email to php-notes+get-37137@lists.php.net to get a copy of this message
/** * Replace node contents * * Needed as a workaround for bug/feature of set_content * This version puts the content * as the first child of the new node. * If you need it somewhere else, simply * move $newnode->set_content() where * you want it. */ function replace_content( &$node, &$new_content ) { $dom =& $node->owner_document(); $newnode =& $dom->create_element( $node->tagname ); $newnode->set_content( $new_content ); $atts =& $node->attributes(); foreach ( $atts as $att ) { $newnode->set_attribute( $att->name, $att->value ); } $kids =& $node->child_nodes(); foreach ( $kids as $kid ) { if ( $kid->node_type() != XML_TEXT_NODE ) { $newnode->append_child( $kid ); } } $node->replace_node( $newnode ); } -- http://www.php.net/manual/en/function.domnode-set-content.php http://master.php.net/manage/user-notes.php?action=edit+25419 http://master.php.net/manage/user-notes.php?action=delete+25419 http://master.php.net/manage/user-notes.php?action=reject+25419

« previous php.notes (#37137) next »