Ask a Question related to PHP Bugs, Design and Development.
-
rrichards@php.net #1
#37669 [Asn->Bgs]: Setting a node's value from array returned by xpath does not work
ID: 37669
Updated by: [email]rrichards@php.net[/email]
Reported By: [email]justinpatrin@php.net[/email]
-Status: Assigned
+Status: Bogus
Bug Type: SimpleXML related
Operating System: Linux (Gentoo, RHEL)
PHP Version: 5.1.4
Assigned To: helly
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
[url]http://www.php.net/manual/[/url] and the instructions on how to report
a bug at [url]http://bugs.php.net/how-to-report.php[/url]
You have to use DOM there. All you were doing was replacing the item at
index 0 in the $nodes array with the string "World".
Previous Comments:
------------------------------------------------------------------------
[2006-06-20 14:25:24] [email]tony2001@php.net[/email]
Marcus, could you pla take a look at it?
------------------------------------------------------------------------
[2006-06-02 04:39:49] [email]justinpatrin@php.net[/email]
I've come up with a workaround which imports the SimpleXML obkect into
DOM and then converts back, but this, of course, defeats the purpose of
SimpleXML. For reference I will post it here for others who need a
solution to this problem:
$domnode = dom_import_simplexml($xml);
$dom = new DOMDocument();
$domnode = $dom->importNode($domnode, true);
$dom->appendChild($domnode);
$x = new DOMXPath($dom);
$n = $x->evaluate('/root/node');
while ($n->item(0)->firstChild) {
$n->item(0)->removeChild($n->firstChild);
}
$n->item(0)->appendChild($dom->createTextNode('World'));
$xml = simplexml_import_dom($dom);
------------------------------------------------------------------------
[2006-06-02 00:44:25] [email]justinpatrin@php.net[/email]
Description:
------------
When trying to set the value (inside text) of a node from an array
returned from an xpath call nothing happens. Setting an attribute works
fine, however. Setting via normal -> access works as expected.
Reproduce code:
---------------
$xml = simplexml_load_string('<root><node/><node2/></root>');
if (is_array($nodes = $xml->xpath('node'))
&& sizeof($nodes) > 0
&& is_object($nodes[0])) {
$nodes[0]['value'] = 'Hello';
$nodes[0] = 'World';
}
$xml->node2 = 'World';
header('Content-Type: text/xml');
echo $xml->asXML();
Expected result:
----------------
<root><node value="Hello">World</node><node2>World</node2></root>
Actual result:
--------------
<root><node value="Hello"/><node2>World</node2></root>
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=37669&edit=1[/url]
rrichards@php.net Guest
-
#40508 [NEW]: Namespace xpath doesn't work for nested elements
From: vrana@php.net Operating system: Windows PHP version: 5.2.1 PHP Bug Type: SimpleXML related Bug description: Namespace... -
#39882 [NEW]: no array being returned from function
From: testuser at phpizabi dot net Operating system: CENT OS 4.4 i686 PHP version: 4.4.4 PHP Bug Type: Arrays related Bug... -
how to access the array returned from xmlsearch
I am having an xmlsearch function, from which i am getting the attributes of the nodes, which satisfy Only one element is returned that is ... -
DataTable from an array of objects returned from a webservice
I have the "simple" problem of wanting to take an array of objects I get from a webservice and turning them into a DataTable. The following is my... -
#24879 [Bgs]: Some data lost in returned array by mysql_fetch_array
ID: 24879 User updated by: sm at grand-prix dot ru Reported By: sm at grand-prix dot ru Status: Bogus Bug Type: ...



Reply With Quote

