-1

Good, I created an XML document with the name and title of songs and artists within that document come also the corresponding cover. Now the link of my XML file is: http://inlivefm.96.lt/nw.xml .

I also have another XML document that gives me the name and artist title that this amounts to the moment (ADELE - HELLO) Now the link of my XML file is: http://inlivefm.96.lt/NowOnAir.xml .

Well, what I'm trying to make is that with document I created give me the cover of this song to give right now. I tried to make a code but to no avail in PHP, so I came to ask your help to get success. Here I leave the code I am using to try to get what I want.

<?php
$xml = simplexml_load_file('http://inlivefm.6te.net/agora.xml');
$artist = urlencode($xml->Event->Song->Artist['name']);
$track = urlencode($xml->Event->Song['title']);
$url = simplexml_load_file("http://inlivefm.96.lt/nw.xml");
$largeImage = $url->xpath('/ilm/$artist- $track/image[@size="cover"]')[0];
echo '<img src="'.$largeImage.'" />';     
?>

Can you please help me doing this?

Thank you all in advance.

Andy Cruz
  • 87
  • 9

1 Answers1

1

correct xpath to take image is

(/ilm/artist/image[@size="cover"])[count(/ilm/artist/name[.="ADELE-HELLO"]/preceding-sibling::name)+1]

because you need to get image with the same position as artist's name.

In php code it should be something like this:

$XML = simplexml_load_file('http://inlivefm.6te.net/agora.xml');
$artist = $XML->Event->Song->Artist['name']; 
$track = $XML->Event->Song['title']; 

$URL = simplexml_load_file("http://inlivefm.96.lt/nw.xml"); 
$largeImage = $URL->xpath('(/ilm/artist/image[@size="cover"])[count(/ilm/artist/name[.="'. $artist .' - '. $track.'"]/preceding-sibling::name)+1]'); 
echo '<img src = "'. $largeImage[0]. '" />'; 
splash58
  • 26,043
  • 3
  • 22
  • 34
  • I inserted this already corrected code and I'm not getting, I did something wrong? php xml simplexml_load_file = $ ('inlivefm.96.lt/agora.xml'); $ artist = urlencode ($ XML-> Event-> Song-> Artist ['name']); $ track = urlencode ($ XML-> Event-> Song ['title']); $ url = simplexml_load_file ("inlivefm.96.lt/nw.xml"); $ largeImage = $ URL-> xpath ('(/ ilm / artist / image [@ size = "cover"]) [count (/ ilm / name [. = "'. $ artist .'- '. $ track.' "] / preceding-sibling :: name) +1] ') [0]; echo ''; ?> – Andy Cruz Jan 03 '16 at 15:50
  • @spalsh58 I could already get what you want through your code, thank you good year for you! – Andy Cruz Jan 03 '16 at 16:25
  • @spalsh58 Sorry to be a bother, the code was working but now changed xml song for ARIANA GRANDE - ONE LAST TIME and cover not updated, you know why? Thank you in advance – Andy Cruz Jan 03 '16 at 18:20
  • the only problem may be, i think, that there are not spaces wrpping hyphen. Test value – splash58 Jan 03 '16 at 18:29
  • @spalsh58 I could already feel the problem is in the "+1" has to be "+2", does not exist any way to do this automatic? because if I change the music the cover is the same. – Andy Cruz Jan 03 '16 at 18:51
  • @spalsh58 In my document with the updated code is still the cover of Adele and has not changed for Ariana Grande, I do not know if what I intend to be able to do. – Andy Cruz Jan 03 '16 at 19:12
  • @spalsh58 Yes, I use them in echo (php) and it updates the song name, what's weird is that he will not seek the name of the song and the artist to the xml document and remove the image which just happens to Adele – Andy Cruz Jan 03 '16 at 19:23
  • So it works`$artist = 'ARIANA GRANDE '; $track = ' ONE LAST TIME'; $URL = simplexml_load_file("http://inlivefm.96.lt/nw.xml"); $largeImage = $URL->xpath('(/ilm/artist/image[@size="cover"])[count(/ilm/artist/name[.="'. $artist .'-'. $track.'"]/preceding-sibling::name)+1]'); echo '';` – splash58 Jan 03 '16 at 19:33
  • It works! but the title and the artist change the cover not updated, I wanted to do the kind LastAPI seeking the image depending on the artist we want, I do not want to bore not exist solution I seek another solution – Andy Cruz Jan 03 '16 at 19:51
  • Sorry, i don't understand - i changed atrist and track variables and got different images. – splash58 Jan 03 '16 at 19:54
  • Does not have to apologize, I prentendo is that this link http://inlivefm.6te.net/agora.xml which is a music software, so this always changing the music, it tells the title and artist , which I thought was to create an XML document http://inlivefm.6te.net/nw.xml with the artist's name, title and the cover and create a code (php echo) that allow removing the image song he was to give at the moment and when I took the song in agora.xml docuemnto you upgraded it alone, but if not we can and give their part have to thank all the effort I decide otherwise – Andy Cruz Jan 03 '16 at 20:13