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 8611807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:27:54+00:00 2026-06-12T04:27:54+00:00

I am new to PHP and I am trying to read the output of

  • 0

I am new to PHP and I am trying to read the output of an XML file that resides on a folder on my local box. In the PHP.net/simplexml_load_file tutorial the following LIKE code should show the SimpleXMLElement Object when I do a print_r($xml). But when I run the script on my local terminal I get the file path:

/Users/msavoy/XMLSourceDir/sfly-6×8.000020513524-7001536_28935-tb.33.xml

I need to be able to get the $xml object so that I can display all the elements within the object.

Here is my code:

// Get the correct count of the values in the $sourceXmlDir after the unset function completes
$sourceXmlArray = array_values($sourceXmlDir);
$count_xml_files = count($sourceXmlArray);

// Check to ensure that there are xml files in the directory before processing parsing the file
// If no files exist create an Exception and log the error.
if ($count_xml_files > 0) {

    // Cycle through the XML files in the $sourceXmlArray
    for ($i = 0; $i < $count_xml_files; $i++) {

        $xml = ($sourceDir . '/' . $sourceXmlArray[$i]);

        print_r($xml);
    }
} else {
    $error_output = date('Y-m-d H:i:s') . 'There are no XML files in the source directory: ' . $sourceDir;
    error_log(date('Y-m-d H:i:s') . 'There are no XML files in the source directory: ' . $sourceDir);
    throw new Exception($error_output);
}

What am I missing? Any help/direction would be appreciated. Regards.

  • 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-12T04:27:55+00:00Added an answer on June 12, 2026 at 4:27 am
    $xml = ($sourceDir . '/' . $sourceXmlArray[$i]);
    
    print_r($xml);
    

    You didn’t actually call simplexml_load_file, so why would $xml be a SimpleXMLElement object?

    Try this:

    $xml = simplexml_load_file($sourceDir . '/' . $sourceXmlArray[$i]);
    
    print_r($xml);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read the iTunes XML file with PHP. I want to extract
I am trying to have PHP read an XML file and then convert it
In PHP, I'm trying to read an Excel file using COM(): $rrc_app = new
I'm trying to read a XML file and output the values, but i'm getting
I'm trying to read XML that is being pushed to my java app. I
I am trying to read in a file that has HTML list items with
I have some simple text file. I am trying to read that file contents
I am new to php, and I am trying to read the contents of
I'm very new at JSON, I'm trying to read one parameter of this file
I am new to php and trying to write a login function. Bit stuck

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.