For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > December 2004 > Re: simplexml question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: simplexml question
Janwillem Borleffs

2004-12-21, 3:57 pm

MyListforSanta wrote:
> Hi


Please don't multipost! Already answered in alt.comp.lang.php:

MyListforSanta wrote:
> Parse error: parse error, unexpected T_OBJECT_OPERATOR in
> /home/findmeth/public_html/uknetholidays/index.php on line 17
>
> I think the error is being caused by the store-offers element as when
> I remove this I dont get the error
>
> Any ideas?
>


The major problem is the hyphen in some of the element names. This triggers
an error.

Since removal of these hyphens isn't an option, you should put them within
curly brackets:

$object->{'store-offers'}

Additionally, I find the xpath method always to be more convenient. Try:

$xml = @simplexml_load_file('xmlfile') or die;
$xpath = "//result/domain/domain-listing/store-offers/store-offer";

foreach ($xml->xpath($xpath) as $storeoffer) {
printf("Store Name %s\n", $storeoffer->{'store-name'});
}


JW



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com