Re: SimpleXML returning Object names with hyphens
| From: | Jochem Maas | Date: | Fri, 23 Dec 2005 10:32:18 +0000 |
| Subject: | Re: SimpleXML returning Object names with hyphens | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-227839@lists.php.net to get a copy of this message | ||
Charlie Davis wrote:
Hey all, I've run into a snag trying to use some XML output from NOAA.what NOAA when its at home?
The problem is that some of the fields it sends to me have a hyphen in the name. Simple XML then creates objects with hyphens in their name.
So here's the object I am having issues with:
object(SimpleXMLElement)#7 (2) {
wind-speed => object(SimpleXMLElement)#9 (2) {
name => string(10) Wind Speed
value => array(37) {
0 => string(1) 4
1 => string(1) 4
...
33 => string(3) 328
34 => string(3) 338
35 => string(3) 350
36 => string(3) 350
you could have trimmed that down a bit.
first turn up error reporting to full error_reporting( E_ALL | E_STRICT );}} } And here's my code issues: $xmlobj->data->parameters->direction access works fine. $xmlobj->data->parameters->direction->value works fine. Gives me the array.
$xmlobj->data->parameters->wind-speed returns an int value of 0. $xmlobj->data->parameters->wind-speed->value gives me an error:then try something like (I'm guessing this might work, then again the behaviour of simpleXML [especially auto/magic casting] is greek to me): $xmlobj->data->parameters->{'wind-speed'} $xmlobj->data->parameters->{'wind-speed'}->value
Parse error: parse error, unexpected T_OBJECT_OPERATOR in noaa.php on line 59 So, what am I doing wrong? The only thing I can think of is the - in the wind-speed object name. Any help would be appreciated! -Charlie