From:             
Operating system: Mac OS X 10.7.2
PHP version:      5.4.0RC3
Package:          SimpleXML related
Bug Type:         Bug
Bug description:SimpleXML doesn't like empty elements with attributes

Description:
------------
If the first XML element is an empty tag, e.g. <link term="no"/>, then no
elements by that name will get recognized. However, if you have many, e.g.
<link> elements, and you write at least the first one as a non-empty tag,
e.g. <link term="no"></link> SimpleXML will recognize all the elements
(even those with empty tags. A test program that uses a test file on my web
site shows this problem.

Test script:
---------------
$fn = "http://www.rajsingh.org/poiwg/c_error.xml";;
$xml = simplexml_load_file($fn);

if ( !empty($xml->link) ) {
  echo "number of links: " . sizeof($xml->link) . "\n";
  foreach ($xml->link as $link) {
    echo "link href: " . $link['href'] . "\n";
  }
}

if ( !empty($xml->relationship) ) {
  echo "number of relationships: " . sizeof($xml->location->relationship) .
"\n";
  foreach ($xml->location->relationship as $rel) {
    echo "relationship term: " . $rel['term'] . "\n";
  }
}

Expected result:
----------------
number of links: 3
link href: http://www.rajsingh.org/pois/45343489.xml
link href: http://en.wikipedia.org/wiki/Boston
link href: http://www.geonames.org/maps/google_42.358_-71.06.html
number of relationships: 3
relationship term: contains
relationship term: within
relationship term: contains


Actual result:
--------------
number of links: 3
link href: http://www.rajsingh.org/pois/45343489.xml
link href: http://en.wikipedia.org/wiki/Boston
link href: http://www.geonames.org/maps/google_42.358_-71.06.html


-- 
Edit bug report at https://bugs.php.net/bug.php?id=60517&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=60517&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=60517&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=60517&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=60517&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60517&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=60517&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=60517&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=60517&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=60517&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=60517&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=60517&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=60517&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=60517&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=60517&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=60517&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60517&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=60517&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=60517&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=60517&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=60517&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=60517&r=mysqlcfg

Reply via email to