|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2005-04-02 17:20 UTC] mbishton at yahoo dot com
 Description:
------------
U.S. library of congress displays house voting activity in xml file. For example: $xml = simplexml_load_file('http://clerk.house.gov/evs/1999/roll610.xml') ;
Many of the elements have dashes in them. For example:
<totals-by-party-header>
<party-header>Party</party-header>
<yea-header>Yeas</yea-header>
<nay-header>Nays</nay-header>
<present-header>Answered ?Present?</present-header>
<not-voting-header>Not Voting</not-voting-header>
Any reference to an element, like;
$xml->totals-by-party-header->party-header->yea-header 
will not work.
Reproduce code:
---------------
It works just fine if the element does not have dashes in it, like:
simplexml_load_file('http://clerk.house.gov/evs/1999/roll610.xml') ;
$vmeta = $xml->xpath('//vote-metadata' ); 
echo 'congress = ' . $vmeta[0]->congress ; 
In the following example, $test will produce an error. 
simplexml_load_file('http://clerk.house.gov/evs/1999/roll610.xml') ;
$meta = $xml->xpath('//totals-by-party' ); 
$test = $meta[1]->yea-total ; 
Expected result:
----------------
I expected it to return an array or the content of an element, depending on what I was referencing. 
Actual result:
--------------
Notice: Use of undefined constant total - assumed 'total' in C:\Program Files\Apache2\htdocs\test01.php on line 9
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 21:00:02 2025 UTC | 
You must encapsulate entries containing dashes. $test = $meta[1]->{'yea-total'}; will work.