hey all, i just want to know why i can't replace a node into an xml tree. here's my code which drives me crazy.

note: i've never used the dom extension ever. is there any hidden information? why the php manual is so confusing on this?

Code:
 $q = "<component><name>test</name><some_element>this is the content</some_element></component>";
 //New Dom Document
 $dom = new DOMDocument();
 $dom->loadXML($xml);
 //new xpath for the query
 $xp = new DOMXPath($dom);
 foreach ($xp->query("//component[name='test']") as $node){
   //Load XML into a new DOM Document object
  $rp = DOMDocument::loadXML($q);
  for( $child = $rp->documentElement->firstChild; $child; $child = $child->nextSibling )
    $node->parentNode->replaceChild( $dom->importNode( $child ), $node);	
}
I also tried the insertBefore() and replaceChild() method but none of them seem to work.

Thanks in advance,

Fotis