You are here: Re: [PHP] SimpleXML returning Object names with hyphens « PHP « IT news, forums, messages
Re: [PHP] SimpleXML returning Object names with hyphens

Posted by Jochem Maas on 12/23/05 12:32

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
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация