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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:31:11+00:00 2026-05-25T11:31:11+00:00

I have a 5MB XML file I’m using the following code to get all

  • 0

I have a 5MB XML file

I’m using the following code to get all nodeValue

$dom = new DomDocument('1.0', 'UTF-8');
if(!$dom->load($url))
    return;

$games = $dom->getElementsByTagName("game");
foreach($games as $game)
{
            
}

This takes 76 seconds and there are around 2000 games tag. Is there any optimization or other solution to get the data?

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

    You shouldn’t use the Document Object Model on large XML files, it is intended for human readable documents, not big datasets!

    If you want fast access you should use XMLReader or SimpleXML.

    XMLReader is ideal for parsing whole documents, and SimpleXML has a nice XPath function for retreiving data quickly.

    For XMLReader you can use the following code:

    <?php
    
    // Parsing a large document with XMLReader with Expand - DOM/DOMXpath 
    $reader = new XMLReader();
    
    $reader->open("tooBig.xml");
    
    while ($reader->read()) {
        switch ($reader->nodeType) {
            case (XMLREADER::ELEMENT):
            if ($reader->localName == "game") {
                 $node = $reader->expand();
                 $dom = new DomDocument();
                 $n = $dom->importNode($node,true);
                 $dom->appendChild($n);
                 $xp = new DomXpath($dom);
                 $res = $xp->query("/game/title"); // this is an example
                 echo $res->item(0)->nodeValue;
            }
        }
    }
    ?>
    

    The above will output all game titles (assuming you have /game/title XML structure).

    For SimpleXML you can use:

    $xml = file_get_contents($url);
    $sxml = new SimpleXML($xml);
    $games = $sxml->xpath('/game'); // returns an array of SXML nodes
    foreach ($games as $game)
    {
       print $game->nodeValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have 0.5MB XML file with data for my iPhone application. It's all
I have a file of 4.5MB (9,223,136 lines) with the following information: 0 0
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have a 60mb XML file that has a list of products, approx 8k
I have a binary file of size about 5MB.. which has lots of interspersed
We have 5mb of typical text (just plain words). We have 1000 words/phrases to
Have just started using Google Chrome , and noticed in parts of our site,
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a program that opens a large binary file, appends a small amount

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.