#46764 [NEW]: attributes() not working properly after xpath()
| From: | maras3000 at gmail dot com | Date: | Fri, 05 Dec 2008 14:29:47 +0000 |
| Subject: | #46764 [NEW]: attributes() not working properly after xpath() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-131630@lists.php.net to get a copy of this message | ||
From: maras3000 at gmail dot com
Operating system: Windows XP (not checked others)
PHP version: 5.2.7
PHP Bug Type: SimpleXML related
Bug description: attributes() not working properly after xpath()
Description:
------------
When looking for list of values of a certain attribute in xml via xpath()
method, the returned SimpleXMLElement object's attributes() method does not
properly return array of attributes.
Reproduce code:
---------------
test.xml:
<?xml version="1.0"?>
<test>
<sth attr="1" />
<sth attr="2" />
<sth attr="3" />
</test>
index.php:
<pre>
<?php
$xml = simplexml_load_file('./test.xml');
$result = $xml->xpath('//@attr');
foreach($result as $node)
{
var_dump($node);
foreach($node->attributes() as $attribute => $value)
echo $atribute . " = " . (string)$value . "\n";
echo "---\n";
}
?>
</pre>
Expected result:
----------------
object(SimpleXMLElement)#2 (1) {
["@attributes"]=>
array(1) {
["attr"]=>
string(1) "1"
}
}
attr = 1
---
object(SimpleXMLElement)#3 (1) {
["@attributes"]=>
array(1) {
["attr"]=>
string(1) "2"
}
}
attr = 2
---
object(SimpleXMLElement)#4 (1) {
["@attributes"]=>
array(1) {
["attr"]=>
string(1) "3"
}
}
attr = 3
---
Actual result:
--------------
object(SimpleXMLElement)#2 (1) {
["@attributes"]=>
array(1) {
["attr"]=>
string(1) "1"
}
}
---
object(SimpleXMLElement)#3 (1) {
["@attributes"]=>
array(1) {
["attr"]=>
string(1) "2"
}
}
---
object(SimpleXMLElement)#4 (1) {
["@attributes"]=>
array(1) {
["attr"]=>
string(1) "3"
}
}
---
--
Edit bug report at http://bugs.php.net/?id=46764&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46764&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46764&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46764&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=46764&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46764&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=46764&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=46764&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=46764&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=46764&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=46764&r=support
Expected behavior: http://bugs.php.net/fix.php?id=46764&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=46764&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=46764&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=46764&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46764&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46764&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=46764&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=46764&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=46764&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=46764&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=46764&r=mysqlcfg