Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are only two php APIs that are really suited for processing large files. The first is the old <a href="http://se2.php.net/manual/en/book.xml.php" rel="nofollow noreferrer">expat</a> api, and the second is the newer <a href="http://se2.php.net/manual/en/book.xmlreader.php" rel="nofollow noreferrer">XMLreader</a> functions. These apis read continuous streams rather than loading the entire tree into memory (which is what simplexml and DOM does).</p> <p>For an example, you might want to look at this partial parser of the DMOZ-catalog:</p> <pre><code>&lt;?php class SimpleDMOZParser { protected $_stack = array(); protected $_file = ""; protected $_parser = null; protected $_currentId = ""; protected $_current = ""; public function __construct($file) { $this-&gt;_file = $file; $this-&gt;_parser = xml_parser_create("UTF-8"); xml_set_object($this-&gt;_parser, $this); xml_set_element_handler($this-&gt;_parser, "startTag", "endTag"); } public function startTag($parser, $name, $attribs) { array_push($this-&gt;_stack, $this-&gt;_current); if ($name == "TOPIC" &amp;&amp; count($attribs)) { $this-&gt;_currentId = $attribs["R:ID"]; } if ($name == "LINK" &amp;&amp; strpos($this-&gt;_currentId, "Top/Home/Consumer_Information/Electronics/") === 0) { echo $attribs["R:RESOURCE"] . "\n"; } $this-&gt;_current = $name; } public function endTag($parser, $name) { $this-&gt;_current = array_pop($this-&gt;_stack); } public function parse() { $fh = fopen($this-&gt;_file, "r"); if (!$fh) { die("Epic fail!\n"); } while (!feof($fh)) { $data = fread($fh, 4096); xml_parse($this-&gt;_parser, $data, feof($fh)); } } } $parser = new SimpleDMOZParser("content.rdf.u8"); $parser-&gt;parse(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload