[OT?] content of text nodes

From: Date: Tue, 03 Jun 2003 03:50:01 +0000
Subject: [OT?] content of text nodes
Groups: php.xml.dev 
Request: Send a blank email to php-xml-dev+get-122@lists.php.net to get a copy of this message
I'm sorry if this is considered off-topic for this list, but I would like to have something resolved, and this seems like the place where I will get a correct answer :) Because in the current version of PHP (4.3) domxml lists get_content() and set_content() as deprecated, I was wondering what are the "correct" ways of: (1) retrieving the content of a text node (2) changing the content of a text node (3) setting the content when there is no text child My current solutions are: (1) $nodeset = $dom->get_elements_by_tagname("test"); $first_node = $nodeset[0]; $text_node = $first_node->first_child(); if ($text_node->node_type == XML_TEXT_NODE) $content = $text_node->node_value; } (2) For this, if we can't use set_content, we have to actually replace the text node which seems wasteful: $nodeset = $dom->get_elements_by_tagname("test"); $first_node = $nodeset[0]; $text_node = $first_node->first_child(); $new_node = $dom->create_text_node("new content"); $text_node->replace($new_node); (3) $nodeset = $dom->get_elements_by_tagname("test"); $first_node = $nodeset[0]; if (!$first_node->first_child()){ $new_node = $dom->create_text_node("first content"); $first_node->append_child($new_node); } Any clarity, corrections or thoughts would be greatly appreciated. Cheers, Eric

« previous php.xml.dev (#122) next »