Note that there are some explanatory texts on larger screens.

plurals
  1. POExtract multiple specific XML attributes using PHP
    primarykey
    data
    text
    <p>I'm trying to extract several attributes from an XML file generated by a piece of software but I'm having no luck.</p> <p>The code I have so far looks like this;</p> <pre><code>$xml_feed_url = 'http://localhost/rest/getNowPlaying.view?u=USERNAMEt&amp;p=PASSWORD&amp;v=1.8.0&amp;c=test'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $xml_feed_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $xml = curl_exec($ch); curl_close($ch); echo $xml; </code></pre> <p>This code successfully outputs the following XML file; </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"&gt; &lt;nowPlaying&gt; &lt;entry id="1805" parent="1798" title="Too Close" album="The Lateness Of The Hour" artist="Alex Clare" isDir="false" coverArt="1798" created="2012-05-22T13:12:29" duration="256" bitRate="320" track="4" discNumber="1" year="2011" genre="Pop" size="10283678" suffix="mp3" contentType="audio/mpeg" isVideo="false" path="Alex Clare/The Lateness Of The Hour/Alex Clare - Too Close.mp3" albumId="50" artistId="14" type="music" username="RestClient" playerId="8" minutesAgo="0"/&gt; &lt;entry id="33664" parent="33642" title="Hot Ride" album="Always Outnumbered, Never Out Gunned" artist="The Prodigy" isDir="false" coverArt="33642" created="2012-05-10T00:31:16" duration="276" bitRate="128" track="5" discNumber="1" year="2004" genre="Other" size="5135448" suffix="mp3" contentType="audio/mpeg" isVideo="false" path="The Prodigy/Always Outnumbered, Never Out Gunned/The Prodigy - Hot Ride.mp3" albumId="2064" artistId="635" type="music" username="Revenant" playerId="6" playerName="test" minutesAgo="3"/&gt; &lt;/nowPlaying&gt; &lt;/subsonic-response&gt; </code></pre> <p>I'm able to successfully extract specific attributes using a foreach loop (below), but I'm looking to extract specific multiple attributes from one user rather than them all.</p> <pre><code>foreach($xml-&gt;children()-&gt;children() as $second_gen){ echo "User: ".$second_gen['username']; echo "Artist: ".$second_gen['artist']; echo "Title: ".$second_gen['title']; echo "Album: ".$second_gen['album']; </code></pre> <p>Any ideas would be appreciated. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload