Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Simplexml problem
Hi

Sorry if this is not the right newsgroup to ask this question but I am
having a problem with simplexml in PHP5.

This is the code I have

$xml = @simplexml_load_file('xmlfile') or die;

foreach ($xml->result->phrase as $phrase) {
printf("Title %s\n", $phrase->title);
printf("Url %s\n", $phrase->url);
printf("Desc %s\n", $phrase->desc);
printf("Review-url %s\n", $phrase->reviewurl);
}

foreach ($xml->result->domain->domain-listing->store-offers->store-offer as
$storeoffer) {
printf("Store Name %s\n", $storeoffer->store-name);
printf("Store Logo %s\n", $storeoffer->store-logo);
printf("In Stock %s\n", $storeoffer->in-stock);
printf("Offer Price %s\n", $storeoffer->offer-price);
printf("Tax %s\n", $storeoffer->tax);
printf("Shipping %s\n", $storeoffer->shipping);
printf("Total Price %s\n", $storeoffer->total-price);
printf("Offer Url %s\n", $storeoffer->offer-url);
printf("Store Rating %s\n", $storeoffer->store-rating);
printf("Store Rating Image %s\n", $storeoffer->store-rating-image);
printf("Num Store Reviews %s\n", $storeoffer->num-store-reviews);
printf("Store Review Url %s\n", $storeoffer->store-review-url);

}

When I try to process this I get an error on this line foreach
($xml->result->domain->domain-listing->store-offers->store-offer as
$storeoffer) {

the error is

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?

I cant change the structure of the xml file as it is supplied by a third
party

Thanks in anticipation

Keith
http://www.mylistforsanta.com



Report this thread to moderator Post Follow-up to this message
Old Post
MyListforSanta
12-20-04 08:56 PM


Re: Simplexml problem
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




Report this thread to moderator Post Follow-up to this message
Old Post
Janwillem Borleffs
12-21-04 08:57 PM


Re: Simplexml problem
"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:41c850f8$0$45943$a344fe98@news.euronet.nl...
> MyListforSanta wrote: 
>
> 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
>
>
>

Thanks for that - the xpath idea works a treat ;-)



Report this thread to moderator Post Follow-up to this message
Old Post
MyListforSanta
12-22-04 01:57 PM


Re: Simplexml problem
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




Report this thread to moderator Post Follow-up to this message
Old Post
Janwillem Borleffs
12-23-04 08:58 PM


Re: Simplexml problem
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




Report this thread to moderator Post Follow-up to this message
Old Post
Janwillem Borleffs
12-26-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:11 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.