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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:43:29+00:00 2026-06-17T02:43:29+00:00

I am trying to get information from external large xml files; from file 1

  • 0

I am trying to get information from external large xml files; from file 1 (vehicleList.xml) and file 2 (CheckVehicles.xml) into a PHP file. All values in XML file 2 are in XML file 1. I would like to display only values in file 1 that are in XML file 2.

My foreach loop code can bring results for up to 130 items (that is if I reduce the items in XML file 2 to 130 items/nodes). However if I remove the if statement, I am able to get all the 3340 items/vehicles from XML file 1.

Where am I going wrong? I tried arrays but failed.

Here is my code:

//XML FILE 1 with 1300 items
$myXML = new SimpleXMLElement('CheckVehicles.xml', NULL, TRUE);//
foreach($myXML->root->item as $item){
        $listArrayNew[(int)$item->value] = (int)$item->value;
}

//XML FILE 2 with 3340 vehicles
$parser = new SimpleXMLElement('vehicleList.xml', NULL, TRUE);
foreach ($parser->GetVehiclesListResponse->GetVehiclesListResult->Vehicle as $Vehicle) {
    if($listArrayNew[(int)$Vehicle->ID] == (int)$Vehicle->ID){
        $vehicle    = $Vehicle->Description;    
        $regNumber  = $Vehicle->RegistrationNumber; 
        $siteID     = $Vehicle->SiteID;     
        $row       .= "<tr>
                            <td>".$vehicle."</td>
                            <td>".$regNumber."</td>
                            <td>".$siteId."</td>
                        </tr>"; 

    }
}

Here are the XML files:

XML file 1: vehicleList.xml

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope>
  <GetVehiclesListResponse>
    <GetVehiclesListResult>
      <Vehicle>
        <ID>153</ID>
        <SiteID>11</SiteID>
        <GroupID>3</GroupID>
        <Description>A.O Basid KAR 459 E</Description>
        <RegistrationNumber>KAR 459 E</RegistrationNumber>
      </Vehicle>

      ..............................


      <Vehicle>
        <ID>3340</ID>
        <SiteID>25</SiteID>
        <GroupID>4</GroupID>
        <Description>UAR 712B White Nissan Tiida (Deus Mubangizi)</Description>
        <RegistrationNumber>UAR 712B</RegistrationNumber>
      </Vehicle>
    </GetVehiclesListResult>
  </GetVehiclesListResponse>
</soap:Envelope>

XML file 2: CheckVehicles.xml

<?xml version="1.0" encoding="utf-8"?>
<Result>
  <root>
    <item>
      <index>0</index>
      <value>153</value>
    </item>

   ...................

    <item>
      <index>1300</index>
      <value>128</value>
    </item>
  </root>
</Result>
  • 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-17T02:43:30+00:00Added an answer on June 17, 2026 at 2:43 am

    I don’t know where you go wrong in your case. However if you want to select elements from the second file based on a criteria (e.g. an ID / unique Number) from the first file I suggest you make use of xpath in your case:

    • Obtain the numbers from the first file that are the criteria (e.g. /*/root/item/value)
    • Select all elements from the second file that match the criteria (e.g. ID in /*/GetVehiclesListResponse/GetVehiclesListResult/Vehicle).

    The later point can best be achieved by using the technique outlined in Is there anything for XPATH like SQL “IN”? which is creating a comma separated list of the numbers to select and then compare this against each elements number.

    Example:

    Consider there 2 500 out of 10 000 elements in a first file and in a second file there are 10 000 elements. Each element can be uniquely identified by it’s ID.

    The first file has this layout:

    <?xml version="1.0"?>
    <root>
        <item>
            <index>0</index>
            <id>604</id>
        </item>
        <item>
            <index>1</index>
            <id>2753</id>
        </item>
        ...
    </root>
    

    And the second file has this layout.

    <?xml version="1.0"?>
    <list>
        <item>
            <id>1</id>
            <some>Number: 33</some>
        </item>
        <item>
            <id>2</id>
            <some>Number: 35</some>
        </item>
        ...
    </list>
    

    The xpath query to get all IDs from the first file therefore is:

    //item/id
    

    And the query for the second file can be expressed with SimpleXML in PHP as:

    $ids   = implode(',', $file1->xpath('//item/id'));
    $query = '//item[contains(",' . $ids . ',", concat(",", id, ","))]';
    

    You can find example code of that example here: http://eval.in/6370

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

Sidebar

Related Questions

I'm trying to get information from a cookie into Alfresco Share. I have a
Hi all I am trying to get contact information from the contact database using
Hi I am trying to get information on an Oracle package directly from PHP
Trying to get information from an external source, I'm receiving the following error: Warning
I am trying to get version information from a file. My code works perfectly
I'm trying to get information from a site by parsing/scraping it via PHP &
I am trying to get information from Activity B, into Activity A, the problem
I am trying to get information from my database and put it into a
I'm trying to get information from a data table .txt file from a list
I'm trying to get information from this site: http://www.gocrimson.com/sports/mbkb/2011-12/roster If you look at that

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.