Last active
August 29, 2015 14:01
-
-
Save catalint/76abfc125631670649e2 to your computer and use it in GitHub Desktop.
Simple class to parse BIG xml files without loading them in memory. It parses one tag a time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$reader = new XMLReaderToSimpleXML(); | |
$reader->open($filePath); | |
while($package = $reader->nextElement('Package')){ | |
parsePackage($package); // edit this to do the parsing stuff | |
} | |
class XMLReaderToSimpleXML extends XMLReader{ | |
function nextElement($tagName){ | |
while($this->read()){ | |
if($this->localName == $tagName && $this->nodeType == XMLReader::ELEMENT){ | |
return simplexml_load_string($this->readOuterXml()); | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment