Bug #51837 [Fbk->NoF]: XMLReader cannot store values in arrays
| From: | php-bugs at lists dot php dot net | Date: | Mon, 18 Feb 2013 00:34:16 +0000 |
| Subject: | Bug #51837 [Fbk->NoF]: XMLReader cannot store values in arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-176848@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=51837&edit=1
ID: 51837
Updated by: php-bugs@lists.php.net
Reported by: cvb724 at yahoo dot ca
Summary: XMLReader cannot store values in arrays
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: *General Issues
Operating System: CentOS 5
PHP Version: 5.3.2
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2010-05-18 13:20:38] mike@php.net
Works fine here:
$ php -r '$r=new XMLReader(); $r->open("http://www.w3.org/TR/xmldsig-core/signature-example-rsa.xml");
while($r->read()){ if($r->nodeType==XMLReader::TEXT) $var[] = $r->value;}
print_r($var);'
Array
(
[0] => 60NvZvtdTB+7UnlLp/H24p7h4bs=
[1] =>
juS5RhJ884qoFR8flVXd/rbrSDVGn40CapgB7qeQiT+rr0NekEQ6BHhUA8dT3+BC
TBUQI0dBjlml9lwzENXvS83zRECjzXbMRTUtVZiPZG2pqKPnL2YU3A9645UCjTXU
+jgFumv7k78hieAGDzNci+PQ9KRmm//icT7JaYztgt4=
[2] =>
uCiukpgOaOmrq1fPUTH3CAXxuFmPjsmS4jnTKxrv0w1JKcXtJ2M3akaV1d/karvJ
lmeao20jNy9r+/vKwibjM77F+3bIkeMEGmAIUnFciJkR+ihO7b4cTuYnEi8xHtu4
iMn6GODBoEzqFQYdd8p4vrZBsvs44nTrS8qyyhba648=
[3] =>
AQAB
[4] =>
CN=Merlin Hughes,O=Baltimore Technologies\, Ltd.,ST=Dublin,C=IE
[5] =>
CN=Test RSA CA,O=Baltimore Technologies\, Ltd.,ST=Dublin,C=IE
[6] => 970849928
[7] =>
MIICeDCCAeGgAwIBAgIEOd3+iDANBgkqhkiG9w0BAQQFADBbMQswCQYDVQQGEwJJ
RTEPMA0GA1UECBMGRHVibGluMSUwIwYDVQQKExxCYWx0aW1vcmUgVGVjaG5vbG9n
aWVzLCBMdGQuMRQwEgYDVQQDEwtUZXN0IFJTQSBDQTAeFw0wMDEwMDYxNjMyMDda
Fw0wMTEwMDYxNjMyMDRaMF0xCzAJBgNVBAYTAklFMQ8wDQYDVQQIEwZEdWJsaW4x
JTAjBgNVBAoTHEJhbHRpbW9yZSBUZWNobm9sb2dpZXMsIEx0ZC4xFjAUBgNVBAMT
DU1lcmxpbiBIdWdoZXMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALgorpKY
Dmjpq6tXz1Ex9wgF8bhZj47JkuI50ysa79MNSSnF7SdjN2pGldXf5Gq7yZZnmqNt
Izcva/v7ysIm4zO+xft2yJHjBBpgCFJxXIiZEfooTu2+HE7mJxIvMR7buIjJ+hjg
waBM6hUGHXfKeL62QbL7OOJ060vKssoW2uuPAgMBAAGjRzBFMB4GA1UdEQQXMBWB
E21lcmxpbkBiYWx0aW1vcmUuaWUwDgYDVR0PAQH/BAQDAgeAMBMGA1UdIwQMMAqA
CEngrZIVgu03MA0GCSqGSIb3DQEBBAUAA4GBAHJu4JVq/WnXK2oqqfLWqes5vHOt
fX/ZhCjFyDMhzslI8am62gZedwZ9IIZIwlNRMvEDQB2zds/eEBnIAQPl/yRLCLOf
ZnbA8PXrbFP5igs3qQWScBUjZVjik748HU2sUVZOa90c0mJl2vJs/RwyLW7/uCAf
C/I/k9xGr7fneoIW
)
------------------------------------------------------------------------
[2010-05-17 10:14:45] cvb724 at yahoo dot ca
Description:
------------
I have tried every way possible to store the values from an XML sheet using XMLReader in an array.
The XML sheet is valid. I have tried this on two systems now, both with the same problem. Colleagues
cannot find anything wrong either. Example code is below:
CODE:
$reader = new XMLReader();
$url = 'http://xml.com/info.php'; // not a
real URL
$reader->open($url);
$i = 0;
$j = 0;
while ($reader->read())
{
if ($reader->nodeType == XMLReader::ELEMENT)
{
$attr[$i] = $reader->getAttribute("name"); // does not store anything
$attr .= $reader->getAttribute("name"); // stores perfectly
i++;
}
if ($reader->nodeType == XMLReader::TEXT)
{
$val[$j] = $reader->value; // performs the same as above
$val .= $reader->value;
$j++;
}
}
Test script:
---------------
$reader = new XMLReader();
$url = 'http://xml.com/info.php'; // insert a
real URL to test
$reader->open($url);
$i = 0;
while ($reader->read())
{
if ($reader->nodeType == XMLReader::TEXT)
{
$val[$i] = $reader->value; // does not work
//$val .= $reader->value; // for demonstration only, works properly
$i++;
}
}
print_r($val);
Expected result:
----------------
When using a valid URL and XML sheet, "print_r" should print an array of all values
stored.
Actual result:
--------------
Instead, the entire array is empty. As soon as you use .= instead of storing in an array, everything
is printed fine simply using "echo".
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=51837&edit=1