Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You only seem to need to parse and read the data and not edit the XML. With this mind, I would say using a SAX parser is the easier and faster way to do this.</p> <blockquote> <p>SAX is an approach to parse XML documents, but not to validate them. The good thing is that you can use it with both PHP 4 and PHP 5 with no changes. In PHP 4, the SAX parsing is already available on all platforms, so no separate installation is necessary.</p> </blockquote> <p>You basically define a function to be run when a start element is found and another to be run when an end element is found (you can also use one for attributes). And then you do whatever you want with the parsed data.</p> <p>Parsing XML with SAX</p> <pre><code>&lt;? function start_element($parser, $element_name, $element_attrs) { switch ($element_name) { case 'KEYWORDS': echo '&lt;h1&gt;Keywords&lt;/h1&gt;&lt;ul&gt;'; break; case 'KEYWORD': echo '&lt;li&gt;'; break; } } function end_element($parser, $element_name) { switch ($element_name) { case 'KEYWORDS': echo '&lt;/ul&gt;'; break; case 'KEYWORD': echo '&lt;/li&gt;'; break; } } function character_data($parser, $data) { echo htmlentities($data); } $parser = xml_parser_create(); xml_set_element_handler($parser, 'start_element', 'end_element'); xml_set_character_data_handler($parser, 'character_data'); $fp = fopen('keyword-data.xml', 'r') or die ("Cannot open keyword-data.xml!"); while ($data = fread($fp, 4096)) { xml_parse($parser, $data, feof($fp)) or die(sprintf('XML ERROR: %s at line %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); } xml_parser_free($parser); ?&gt; </code></pre> <p>Source: I worked on parsing and processing large amounts of XML data. <strong>EDIT: Better example</strong></p> <p><strong>EDIT: Well, apparently you are already using a Sax Parser. As long as you are actually processing the file in an event driven way (Not having any additional overhead) you should be at top performance in this department. I would say there is nothing you can do to increase the parsing performance. If you are having performance issues I would suggest looking at what you are doing in your code to find performance bottlenekcs (Try using a php profiler like <a href="http://xdebug.org/docs/profiler" rel="nofollow">this one</a> ). If you post your code here, we could give it a look! Cheers!</strong></p>
    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. 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.
 

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