homepage Welcome to WebmasterWorld Guest from 54.196.136.119
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
XML help
Easy question.... I think
grooverince




msg:3136723
 11:29 am on Oct 27, 2006 (gmt 0)

I am trying to display the Artist and Title from this XML feed (http://example.com/NRG_FM.xml) on my php based homepage. I have tried numerous ways of doing it but none of them seem to work. i am a real noob to the world of XML. Can anyone help or at least guide me in the right direction?

Thanks you

[edited by: jatar_k at 12:30 am (utc) on Oct. 31, 2006]
[edit reason] no urls thanks [/edit]

 

Little_G




msg:3136831
 12:54 pm on Oct 27, 2006 (gmt 0)

Hi,

This should do it:

<?php
$file = file_get_contents("http://example.com/NRG_FM.xml");
$doc = new DOMDocument();
$doc->loadXML($file);
foreach($doc->getElementsByTagName('Entry')->item(0)->attributes as $attribute){
if($attribute->name == "Title" $attribute->name == "Artist"){
echo $attribute->name . ": " . $attribute->value . "<br>";
}
}
?>

(ps. you need to change any broken vertical bars to solid vertical bars)

Andrew

[edited by: Little_G at 12:59 pm (utc) on Oct. 27, 2006]

[edited by: jatar_k at 12:30 am (utc) on Oct. 31, 2006]

grooverince




msg:3137939
 12:04 pm on Oct 28, 2006 (gmt 0)

hi thank you very much for you help but I get the following error when I try to run this script:

Parse error: parse error, unexpected T_OBJECT_OPERATOR in f:\webserver\test\playlist.php on line 5

Little_G




msg:3137962
 12:50 pm on Oct 28, 2006 (gmt 0)

Hi,

Are you using PHP5?

Andrew

baron13




msg:3143329
 8:48 am on Nov 2, 2006 (gmt 0)

Hi,
is it necessary to use PHP5 for this?
And how would be the solution for PHP4?

Regards,
Baron

grooverince




msg:3143587
 1:20 pm on Nov 2, 2006 (gmt 0)

I upgraded to PHP5 and now everytime I try to run this script it gives me the following error:

Parse error: parse error, unexpected T_STRING in f:\webserver\playlist.php on line 6

also once this script runs properly how would I go about inserting the info into other php pages?

Little_G




msg:3144041
 7:55 pm on Nov 2, 2006 (gmt 0)

Hi,

Firstly, grooverince, did you change any broken vertical bars to solid vertical bars?

Secondly, baron13, you need to assign the return value of a method to a variable and then call the methods from that, so:
$doc->getElementsByTagName('Entry')->item(0)->attributes

becomes
$a = $doc->getElementsByTagName('Entry')
$a->item(0)->attributes;

I think the above code is right I don't have PHP4 installed so I can't test it.

Andrew

grooverince




msg:3145876
 1:05 pm on Nov 4, 2006 (gmt 0)

Thank you very much for all your help Little G the script works like a charm. Now for the final question, how would I go about displaying the information from this script on a seperate php page?

Little_G




msg:3145895
 2:03 pm on Nov 4, 2006 (gmt 0)

Hi,

The easiest way would probably be to use include [php.net].

Andrew

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved