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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:49:34+00:00 2026-05-26T11:49:34+00:00

I have three xml files that I want to load into my php file

  • 0

I have three xml files that I want to load into my php file with the simplexml_load_string function.

How can I achieve this?

@Jan-Henk:

Here is what I wrote on the comments:

This is what I have at the moment , it searches one xml file for the employee Jane:

$result   = simplexml_load_file('employees1.xml');
echo "<strong>Matching employees with name 'Jane'</strong><br />";
$employees = $result->xpath('/employees/employee[name="Jane"]');

foreach($employees as $employee) {
    echo "Found {$employee->name}<br />";
}
echo "<br />";

How would this look like with three xml files. And then instead of searching for employee Jane like above. It should search the three files for duplicates. So if an employee is listed two times in either of the three files. It should return: “Found Jane”.

  • 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-26T11:49:34+00:00Added an answer on May 26, 2026 at 11:49 am

    Just load all 3 files separately:

    $xmlOne   = simplexml_load_file('path/to/file1.xml');
    $xmlTwo   = simplexml_load_file('path/to/file2.xml');
    $xmlThree = simplexml_load_file('path/to/file3.xml');
    

    If you really want to use simplexml_load_string instead of simplexml_load_file you can do:

    $xmlOne = simplexml_load_string(file_get_contents('path/to/file1.xml'));
    

    Answer for the edit in your question, which only works for the name Jane:

    $files = array('employees1.xml', 'employees2.xml', 'employees3.xml');
    $xpathQuery = '/employees/employee[name="Jane"]';
    $count = 0;
    
    foreach ($files as $file) {
        $xml = simplexml_load_file($file);
        $result = $xml->xpath($xpathQuery);
    
        if (count($result) > 0) {
            $count++;
        }
    }
    
    if ($count > 1) {
        echo "Duplicates for Jane";
    } else {
        echo "No duplicates for Jane";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Updated to be clear. Step One: I have a XML file that I want
I have an xml file that is a project resource. I can access it
I have a XML file that defines a lot of rules. I load the
I have some xml data contained in three files (Database.xml, Participants.xml, and ConditionTokens.xml). I
I have created XML file,but I can't view it/output it.I know there is no
We have a Flex app that is currently loading an XML file that contains
I have a snippet of an XML file that looks like: <?xml version=1.0 encoding=utf-16?>
tl;dr : I want to load an XML file once and reuse it over
I have created MVC application. I want to include js or css file into
Background: In our project, we have a bunch of xml files that define tests

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.