You are here: aliasing and reference confusion.... « PHP Programming Language « IT news, forums, messages
aliasing and reference confusion....

Posted by CptDondo on 12/05/06 00:08

I hope that someone can set me straight on "alaising" and "references"
in PHP....

I'm a C coder from ways back and this "new fangled" PHP way of doing
things is hurting my brain. :-)

OK, to set the background:

I have an XML document. I am searching it using xpath. So far so good.

Now I need to replace a node value. In PHP4 and libxml 2.4, the
node->set_value method doesn't actually set the value; it appends it to
the node value.

So I've built a function setXpathNodeValue:

function setXpathNodeValue($context, $pattern, $snode,
&$new_content ) {

if ($snode == '') $nodeset = xpath_eval($context, $pattern);
else $nodeset = xpath_eval($context, $pattern, $snode);

$arNodes = $nodeset->nodeset;
$node = $arNodes[0];
if ($node == NULL) return NULL;

$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 );
}

(Yes, this comes almost verbatim from the PHP.net docs.)

Except that I can't figure out how to "pass by reference" the $dom so
that it is actually changed in the original. That's the whole point of
this exercise.

I guess I could just copy over the whole $dom, but that's potentially
enormous....

Any suggestions? I am stuck....

--Yan

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация