<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.xml.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.xml-parse.php',
    1 => 'xml_parse',
    2 => 'Commence l\'analyse d\'un document XML',
  ),
  'up' => 
  array (
    0 => 'ref.xml.php',
    1 => 'Fonctions d\'analyse de fichier XML',
  ),
  'prev' => 
  array (
    0 => 'function.xml-get-error-code.php',
    1 => 'xml_get_error_code',
  ),
  'next' => 
  array (
    0 => 'function.xml-parse-into-struct.php',
    1 => 'xml_parse_into_struct',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/xml/functions/xml-parse.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.xml-parse" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">xml_parse</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">xml_parse</span> &mdash; <span class="dc-title">Commence l&#039;analyse d&#039;un document XML</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.xml-parse-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>xml_parse</strong></span>(<span class="methodparam"><span class="type"><a href="class.xmlparser.php" class="type XMLParser">XMLParser</a></span> <code class="parameter">$parser</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$is_final</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>xml_parse()</strong></span> analyse un document XML. Les gestionnaires
   pour les événements configurés sont appelés autant de fois que nécessaire.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.xml-parse-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">parser</code></dt>
     <dd>
      <p class="para">
       Une référence sur l&#039;analyseur XML à utiliser.
      </p>
     </dd>
    
    
     <dt><code class="parameter">data</code></dt>
     <dd>
      <p class="para">
       Une partie des données à analyser. Un document peut être analysé
       morceau par morceau par appels successifs à 
       <span class="function"><strong>xml_parse()</strong></span> avec de nouvelles données, aussi longtemps
       que le paramètre <code class="parameter">is_final</code> est défini et <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>
       lorsque les dernières données sont analysées.
      </p>
     </dd>
    
    
     <dt><code class="parameter">is_final</code></dt>
     <dd>
      <p class="para">
       Si défini et vaut <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, <code class="parameter">data</code> sera le dernier
       morceau de données envoyées à l&#039;analyseur.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.xml-parse-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne 1 en cas de succès ou 0 en cas d&#039;échec.
  </p>
  <p class="para">
   Lors d&#039;un échec d&#039;analyse, la cause de l&#039;erreur peut être obtenue grâce 
   aux fonctions
   <span class="function"><a href="function.xml-get-error-code.php" class="function">xml_get_error_code()</a></span>,
   <span class="function"><a href="function.xml-error-string.php" class="function">xml_error_string()</a></span>,
   <span class="function"><a href="function.xml-get-current-line-number.php" class="function">xml_get_current_line_number()</a></span>,
   <span class="function"><a href="function.xml-get-current-column-number.php" class="function">xml_get_current_column_number()</a></span> et
   <span class="function"><a href="function.xml-get-current-byte-index.php" class="function">xml_get_current_byte_index()</a></span>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Quelques erreurs (dont les erreurs d&#039;entités) sont
    reportées à la fin des données, ceci uniquement
    si <code class="parameter">is_final</code> vaut <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.xml-parse-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">parser</code> attend une instance de <span class="classname"><a href="class.xmlparser.php" class="classname">XMLParser</a></span>
  désormais; auparavent, une <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="literal">xml</code> était attendue.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.xml-parse-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="xml_parse.example.chunked">
   <p><strong>Exemple #1 Analyse de gros documents XML par morceaux</strong></p>
   <div class="example-contents"><p>
    Cet exemple montre comment les gros documents XML peuvent être lus et
    analysés en morceaux, permettant ainsi de ne pas conserver en mémoire
    la totalité du document. Aucun gestionnaire d&#039;erreur n&#039;a été positionné
    pour rendre l&#039;exemple plus concis.
   </p></div>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$stream </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'examples/book-simple.xml'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$parser </span><span style="color: #007700">= </span><span style="color: #0000BB">xml_parser_create</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">xml_set_element_handler</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$parser</span><span style="color: #007700">,<br />    function(</span><span style="color: #0000BB">$parser</span><span style="color: #007700">, </span><span style="color: #0000BB">$name</span><span style="color: #007700">, </span><span style="color: #0000BB">$attributes</span><span style="color: #007700">) { echo </span><span style="color: #0000BB">$name</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; },<br />    function(</span><span style="color: #0000BB">$parser</span><span style="color: #007700">, </span><span style="color: #0000BB">$name</span><span style="color: #007700">) { echo </span><span style="color: #0000BB">$name</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; }<br />);<br /><br />while ((</span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, </span><span style="color: #0000BB">16384</span><span style="color: #007700">))) {<br />    </span><span style="color: #0000BB">xml_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$parser</span><span style="color: #007700">, </span><span style="color: #0000BB">$data</span><span style="color: #007700">); </span><span style="color: #FF8000">// analyse du morceau courant<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">xml_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$parser</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">); </span><span style="color: #FF8000">// finalisation de l'analyse<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);</span></span></code></div>
   </div>

  </div>
 </div>

 
</div><?php manual_footer($setup); ?>