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

  • Home
  • SEARCH
  • 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 3236918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:40:39+00:00 2026-05-17T17:40:39+00:00

Hey guys. I’m trying to parse xml file in order to extract some data

  • 0

Hey guys. I’m trying to parse xml file in order to extract some data from it and display it on the website. However, when I’m using url which doesn’t end with .xml extension I can’t run a foreach loop on the result. In other words when I’m using this kind of url:

$url = http://www.example.com/some_xml_file.xml

I can run a a foreach loop on it and it works like charm. But this time around I have to deal with this type of url:

$url = http://www.example.com/?some_var=something&some=something

So you can clearly see that it doesn’t contain .xml extension. It returns nicely parsed result but I can’t get the foreach loop to work on this result and therefore I can’t extract any data from it. Could you help me with this one?

Example of what I’m doing:

$url = 'http://www.example.com/?some_var=something&some=somethinge';

    $sx = simplexml_load_file($url);

    foreach ($sx->response as $row)
    {
        echo $row['status'];

    }

And this is the result of var_dump($sx):

object(SimpleXMLElement)#334 (2) { ["@attributes"]=>  array(2) { ["status"]=>  string(2) "ok" ["version"]=>  string(3) "1.0" } ["events"]=>  object(SimpleXMLElement)#333 (2) { ["@attributes"]=>  array(3) { ["resultCount"]=>  string(1) "1" ["pageSize"]=>  string(2) "15" ["pageIndex"]=>  string(1) "0" } ["event"]=>  object(SimpleXMLElement)#338 (10) { ["@attributes"]=>  array(1) { ["id"]=>  string(6) "180085" } ["name"]=>  string(27) "Lady Gaga Monster Ball Tour" ["doordatetime"]=>  string(19) "2010-11-01T18:30:00" ["tickets"]=>  object(SimpleXMLElement)#337 (1) { ["ticket"]=>  array(5) { [0]=>  object(SimpleXMLElement)#339 (7) { ["@attributes"]=>  array(1) { ["id"]=>  string(6) "307902" } ["price"]=>  string(7) "£55.00" ["url"]=>  string(32) "http://www.gigjunkie.net/T307902" ["provider"]=>  string(12) "Ticketmaster" ["soldout"]=>  string(5) "false" ["ticketsavailable"]=>  string(4) "true" ["issecondary"]=>  string(5) "false" } [1]=>  object(SimpleXMLElement)#340 (7) { ["@attributes"]=>  array(1) { ["id"]=>  string(6) "426248" } ["price"]=>  string(7) "£82.00" ["url"]=>  string(32) "http://www.gigjunkie.net/T426248" ["provider"]=>  string(8) "Seatwave" ["soldout"]=>  string(5) "false" ["ticketsavailable"]=>  string(4) "true" ["issecondary"]=>  string(4) "true" } [2]=>  object(SimpleXMLElement)#437 (6) { ["@attributes"]=>  array(1) { ["id"]=>  string(6) "306230" } ["url"]=>  string(32) "http://www.gigjunkie.net/T306230" ["provider"]=>  string(7) "Viagogo" ["soldout"]=>  string(5) "false" ["ticketsavailable"]=>  string(4) "true" ["issecondary"]=>  string(4) "true" } [3]=>  object(SimpleXMLElement)#438 (6) { ["@attributes"]=>  array(1) { ["id"]=>  string(6) "325819" } ["url"]=>  string(32) "http://www.gigjunkie.net/T325819" ["provider"]=>  string(15) "WorldTicketShop" ["soldout"]=>  string(5) "false" ["ticketsavailable"]=>  string(4) "true" ["issecondary"]=>  string(4) "true" } [4]=>  object(SimpleXMLElement)#342 (6) { ["@attributes"]=>  array(1) { ["id"]=>  string(6) "402593" } ["url"]=>  string(32) "http://www.gigjunkie.net/T402593" ["provider"]=>  string(14) "Empire Tickets" ["soldout"]=>  string(5) "false" ["ticketsavailable"]=>  string(4) "true" ["issecondary"]=>  string(4) "true" } } } ["venue"]=>  object(SimpleXMLElement)#336 (9) { ["@attributes"]=>  array(1) { ["id"]=>  string(4) "1479" } ["name"]=>  string(13) "Odyssey Arena" ["street"]=>  string(13) "2 Queens Quay" ["town"]=>  string(7) "Belfast" ["nameandtown"]=>  string(22) "Odyssey Arena, Belfast" ["country"]=>  string(2) "GB" ["gjurl"]=>  string(90) "http://www.gigjunkie.net/gigs/Lady-Gaga-Monster-Ball-Tour/Odyssey-Arena/01-Nov-2010/180085" ["latitude"]=>  string(9) "54.602158" ["longitude"]=>  string(9) "-5.918215" } ["gjurl"]=>  string(90) "http://www.gigjunkie.net/gigs/Lady-Gaga-Monster-Ball-Tour/Odyssey-Arena/01-Nov-2010/180085" ["artists"]=>  object(SimpleXMLElement)#341 (1) { ["artist"]=>  object(SimpleXMLElement)#332 (5) { ["@attributes"]=>  array(2) { ["id"]=>  string(5) "54194" ["isprimary"]=>  string(4) "true" } ["name"]=>  string(9) "Lady Gaga" ["gjurl"]=>  string(42) "http://www.gigjunkie.net/artists/Lady-Gaga" ["thumbnailimage"]=>  string(68) "http://images.gigjunkie.net/f5376fab-cd01-4432-9205-8a1d0be41437.jpg" ["mediumimage"]=>  string(68) "http://images.gigjunkie.net/efbe624c-b63d-452a-a89b-221e846147ab.jpg" } } ["iscancelled"]=>  string(5) "false" ["genre"]=>  string(8) "Rock/Pop" ["image"]=>  string(68) "http://images.gigjunkie.net/efbe624c-b63d-452a-a89b-221e846147ab.jpg" } } } 
  • 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-05-17T17:40:39+00:00Added an answer on May 17, 2026 at 5:40 pm

    Your processing doesn’t seem to match with your XML document structure. Your processing seems to be expecting a document like this:

    <some_document>
      <response status="ok">...</response>
      <response status="ok">...</response>
      ...
    </some_document>
    

    However, by the looks of your var_dump, that’s not how the actual document is structured. That’s why you can’t iterate over the “response” elements with foreach() — I don’t think there are any there to iterate over.

    If you can post the actual XML document, we can probably fix up your processing to match it.

    The main thing to bear in mind, I think, is that the way SimpleXMLElement works is that the object you get back is the root of the XML document, so if your document looks like this:

    <response>
       <some_data>...</some_data>
       <some_other_data>...</some_other_data>
    </response>
    

    …then $sx->response won’t exist. $sx is the <response> element, it doesn’t contain it.

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

Sidebar

Related Questions

Hey guys. I'm not much of a programmer, but still need to do some
Hey guys. I'm trying to configure TFS2010 on a home server. I want to
hey guys, I've followed some tutorials online regarding creating and installing a windows service
Hey guys. I am trying to get the selected option in an each loop.
Hey guys, I'm using GWT for a data-driven web application, and I'm having issues
Hey guys I am trying to implement the twitter for posting the comments about
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys i wrote a quick test. I want delete to call deleteMe which
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey right now I'm using jQuery and I have some global variables to hold

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.