Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:20:02+00:00 2026-06-18T16:20:02+00:00

I’m trying to extract several attributes from an XML file generated by a piece

  • 0

I’m trying to extract several attributes from an XML file generated by a piece of software but I’m having no luck.

The code I have so far looks like this;

$xml_feed_url = 'http://localhost/rest/getNowPlaying.view?u=USERNAMEt&p=PASSWORD&v=1.8.0&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;

This code successfully outputs the following XML file;

<?xml version="1.0" encoding="UTF-8"?>
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0">  
  <nowPlaying>  
    <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"/>  
    <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"/>  
  </nowPlaying>  
</subsonic-response>

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.

foreach($xml->children()->children() as $second_gen){  
echo "User: ".$second_gen['username'];  
echo "Artist: ".$second_gen['artist'];  
echo "Title: ".$second_gen['title'];  
echo "Album: ".$second_gen['album'];

Any ideas would be appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:20:03+00:00Added an answer on June 18, 2026 at 4:20 pm

    How about using simple_xml and XPath?

    Something like…

    $username='Revenant';
    $xml->registerXPathNamespace("n", "http://subsonic.org/restapi");
    $result=$xml->xpath("//n:entry[@username='$username']/@title | //n:entry[@username='$username']/@album | //n:entry[@username='$username']/@artist");
    
    echo "$result[0] by $result[2] on the album $result[1]";
    

    Tested with PHP 5.4.4

    Michi

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.