/**
* Replaces 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.
* Credit: http://www.php.net/manual/en/function.domnode-set-content.php
*/
function xml_replace_nodeContent( &$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 );
}
}
return $newnode;
}
PHP and javascript snippets you can copy and paste.
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2007
(71)
-
▼
April
(24)
- js_map_keyPress(actualKeyPress,keyPressToMatch,cal...
- js_get_keyCode(e)
- js_create_socialBookmarks(container,path_to_icons)
- js_ajax.js
- net_upload_photosToFlickr($yourFlickrEmailAddress,...
- js_is_image(ext)
- js_php_parse_url(url)
- file_do_download($fileName)
- xml_replace_nodeContent( &$node, &$new_content )
- arr_add_elementToStart($a,$el)
- fnc_call($funcName)
- sec_quote_SQLStr($sql)
- net_convert_arrayToUrlStr($arr)
- xml_get_nodeChildren($xpathObj,$path,$index=0)
- xml_get_XMLStrFromXPath($xpathObj,$path,$index=0)
- xml_remove_elementsByTagName($parentNode,$tagName)
- xml_append_childNode($parentNode,$childNode)
- xml_create_elementWithText($doc, $name, $value)
- xml_clone_xpathToNewDOM($origXPath,$path)
- xml_create_node($xml)
- xml_create_xpath($DOM)
- xml_create_DOM($xmlStr)
- xml_get_attribValue($node, $name, $default)
- xml_get_nodeSet($xpathObj,$path,$index=0)
-
▼
April
(24)
No comments:
Post a Comment