ID: 50759 Updated by: ahar...@php.net Reported By: stevendamico at gmail dot com -Status: Open +Status: Bogus -Bug Type: Scripting Engine problem +Bug Type: SimpleXML related Operating System: Windows PHP Version: 5.2.12 New Comment:
Per example #5 in http://au2.php.net/manual/en/simplexml.examples-basic.php, the idiomatic way to access attributes in a SimpleXML tree is to access them in the same way as array elements. In your example, this should work (and works for me): echo $doc->...->{'recorded-vote'}->legislator['name-id']; Closing, as this isn't a bug in PHP itself. Thanks for your interest in PHP! Previous Comments: ------------------------------------------------------------------------ [2010-01-14 23:19:47] stevendamico at gmail dot com Description: ------------ Using SimpleXML and SimpleXML_load_file to load an external XML file. The ::attributes feature does not recognize hyphens in attribute features, no documentation on how to resolve feature and the solution for dealing with hyphens in nodes (by putting it in curly braces and quotes {''}) does not solve the problem. This is my first time submitting a bug and I'm an amateur, but there is no documentation for a solution. Not sure if I selected the proper bug category. Sorry for any mistakes. Reproduce code: --------------- --- >From manual page: simplexmlelement.attributes#Description --- portion of xml file (parent nodes left out for simplicity): <recorded-vote><legislator name-id="A000014" sort-field="Abercrombie" unaccented-name="Abercrombie" party="D" state="HI" role="legislator">Abercrombie</legislator><vote>Aye</vote></recorded-vote> ex. 1: echo {'recorded-vote'}[0]->legislator->attributes()->{'name-id'}; ex. 2: print_r ({'recorded-vote'}[0]->legislator->attributes()); Expected result: ---------------- ex. 1 A000014 ex. 2 SimpleXMLElement Object ( [...@attributes] => Array ( [name-id] => A000014 [sort-field] => Abercrombie [unaccented-name] => Abercrombie [party] => D [state] => HI [role] => legislator ) ) Actual result: -------------- ex. 1 0 To clarify, all that outputs is the digit zero. ex. 2 SimpleXMLElement Object ( [...@attributes] => Array ( [party] => D [state] => HI [role] => legislator ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50759&edit=1