473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

aliasing and reference confusion....

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
Dec 4 '06 #1
1 1089

OK, got it figured out....

IN the calling routine:

setXpathNodeValue($dom, $context, $pattern, $snode, $new_content)

And in the function declaration:

setXpathNodeValue(& $dom, $context, $pattern, $snode, $new_content)

and then use $dom. It works....

--Yan
Dec 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: Carl | last post by:
"Nine Language Performance Round-up: Benchmarking Math & File I/O" http://www.osnews.com/story.php?news_id=5602 I think this is an unfair comparison! I wouldn't dream of developing a numerical...
4
by: Yuri Victorovich | last post by:
In short my question is: If I overload "operator new" for class A and return from it instance of struct B (unrelated with A) as allocated memory area for A should aliasing rules work and allow...
3
by: Michel | last post by:
Is there a way I can anti-aliasing a gif to be able to get a hi-quality resizeable backgroundpicture. When a GIF of JPG is being resized by the browser you get wurse pictures because it needs a...
4
by: JMCN | last post by:
object invalid or no longer set - confusion of the recordset in access 2003. i am currently converting from access 97 to access 2003. majority of the codes converted over perfectly fine, though...
9
by: Adam Warner | last post by:
Hi all, Message ID <c1qo3f0tro@enews2.newsguy.com> is one of many informative articles by Chris Torek about C. The particular message discusses aliasing and concludes with this paragraph: ...
3
by: Hallvard B Furuseth | last post by:
I'm getting horribly lost in the strict aliasing rules. Is this code correct? struct A { int x; }; struct B { int x, y; }; int foo( struct A *a ) { struct B *b = (struct B *) a; return b->x...
9
by: toton | last post by:
Hi, Is it possible to alias a class with a different name ? something like typedef template<class T>std::vector<Tindex_type<T; So that then I can write, index_type<std::size_tindex_t; The...
13
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody...
4
by: Paul Brettschneider | last post by:
Hello all, consider the following code: typedef char T; class test { T *data; public: void f(T, T, T); void f2(T, T, T);
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.