Jump to content

[SimpleXML] Assigning values to elements found with XPath


Phasma Felis

Recommended Posts

I want to find all elements named "field" in an XML doc and assign a new value to each one. I'd tried something like this:

 

foreach ($xml->xpath('//field') as &$field)
    $field = $value;

 

But that doesn't work, because (I think) XPath returns a temporary array, not a reference to an actual element. ("PHP Fatal error:  Cannot create references to elements of a temporary array expression")

 

Is there a way to assign values to elements located with XPath, or do I just have to iterate over the whole document?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.