Re: SimpleXML returning Object names with hyphens

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sweet. Thanks!

The {'..'} works perfectly. Never knew about that syntax.

-Charlie

Jochem Maas wrote:
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.

    }
  }
}

And here's my code issues:

$xmlobj->data->parameters->direction access works fine.
$xmlobj->data->parameters->direction->value works fine. Gives me the array.


first turn up error reporting to full

error_reporting( E_ALL | E_STRICT );

$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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux