Skip to content Skip to sidebar Skip to footer

PHP read XML file using SAX parser

Reading Time: < 1 minute

How to php read xml file using SAX parser.SAX means Simple API for XML.The SAX parser is work differently with DOM parser, it either load any XML document into memory not create any object representation of the XML document.
The advantage of a SAX parser is that it’s really lightweight. The parser doesn’t keep anything in memory for very long, so it can be used for extremely large files. The disadvantage is that writing SAX parser callbacks is a big nuisance.

In another article I was describes how to read xml file using php simple example.
Students.xml



  
    Butcher
    French
    [email protected]
	09412345678
  
  
    Smith
    United State
    [email protected]
	094987456258
  
  
    Jack Sparrow
    Carribian
    [email protected]
	094784210308
  

index.php

';
	  echo "Student Name - ".$student['NAME'].'
'; echo "Country - ".$student['COUNTRY'].'
'; echo "Email - ".$student['EMAIL'].'
'; echo "Phone - ".$student['PHONE'].'
'; $i++; } ?>

Demo
Download PHP Read XML file by SAX parser Example(2 KB)
That’s all.