<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.simplexmlelement.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'simplexmlelement.registerxpathnamespace.php',
    1 => 'SimpleXMLElement::registerXPathNamespace',
    2 => 'Cr&eacute;e un contexte pr&eacute;fixe/ns pour la prochaine requ&ecirc;te XPath',
  ),
  'up' => 
  array (
    0 => 'class.simplexmlelement.php',
    1 => 'SimpleXMLElement',
  ),
  'prev' => 
  array (
    0 => 'simplexmlelement.next.php',
    1 => 'SimpleXMLElement::next',
  ),
  'next' => 
  array (
    0 => 'simplexmlelement.rewind.php',
    1 => 'SimpleXMLElement::rewind',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/simplexml/simplexmlelement/registerXPathNamespace.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="simplexmlelement.registerxpathnamespace" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SimpleXMLElement::registerXPathNamespace</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SimpleXMLElement::registerXPathNamespace</span> &mdash; <span class="dc-title">
   Crée un contexte préfixe/ns pour la prochaine requête XPath
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-simplexmlelement.registerxpathnamespace-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SimpleXMLElement::registerXPathNamespace</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$prefix</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$namespace</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Crée un contexte préfixe/ns pour la prochaine requête XPath. En
   particulier, ceci est utile si le fournisseur du document XML donné modifie
   les préfixes d&#039;espace de noms. <code class="literal">registerXPathNamespace</code>
   créera un préfixe pour l&#039;espace de noms associé, autorisant l&#039;accès aux
   nœuds dans cet espace de noms sans avoir besoin de changer le code pour
   autoriser les nouveaux préfixes dictés par le fournisseur.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-simplexmlelement.registerxpathnamespace-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">prefix</code></dt>
     <dd>
      <p class="para">
       Le préfixe d&#039;espace de noms à utiliser dans la requête XPath pour
       l&#039;espace de noms donné dans <code class="parameter">namespace</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">namespace</code></dt>
     <dd>
      <p class="para">
       L&#039;espace de noms à utiliser pour la requête XPath. Ceci doit concorder
       avec un espace de noms qui est utilisé par le document XML, sinon la requête
       XPath qui utilise <code class="parameter">prefix</code> ne retournera aucun
       résultat.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-simplexmlelement.registerxpathnamespace-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Cette fonction retourne <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> en cas de succès ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si une erreur survient.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-simplexmlelement.registerxpathnamespace-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Fixe un préfixe d&#039;espace de noms pour utiliser dans une requête XPath</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$xml </span><span style="color: #007700">= &lt;&lt;&lt;EOD<br /></span><span style="color: #DD0000">&lt;book xmlns:chap="http://example.org/chapter-title"&gt;<br />    &lt;title&gt;My Book&lt;/title&gt;<br />    &lt;chapter id="1"&gt;<br />        &lt;chap:title&gt;Chapter 1&lt;/chap:title&gt;<br />        &lt;para&gt;Donec velit. Nullam eget tellus vitae tortor gravida scelerisque. <br />            In orci lorem, cursus imperdiet, ultricies non, hendrerit et, orci. <br />            Nulla facilisi. Nullam velit nisl, laoreet id, condimentum ut, <br />            ultricies id, mauris.&lt;/para&gt;<br />    &lt;/chapter&gt;<br />    &lt;chapter id="2"&gt;<br />        &lt;chap:title&gt;Chapter 2&lt;/chap:title&gt;<br />        &lt;para&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin <br />            gravida. Phasellus tincidunt massa vel urna. Proin adipiscing quam <br />            vitae odio. Sed dictum. Ut tincidunt lorem ac lorem. Duis eros <br />            tellus, pharetra id, faucibus eu, dapibus dictum, odio.&lt;/para&gt;<br />    &lt;/chapter&gt;<br />&lt;/book&gt;<br /></span><span style="color: #007700">EOD;<br /><br /></span><span style="color: #0000BB">$sxe </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerXPathNamespace</span><span style="color: #007700">(</span><span style="color: #DD0000">'c'</span><span style="color: #007700">, </span><span style="color: #DD0000">'http://example.org/chapter-title'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$sxe</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">xpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'//c:title'</span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$result </span><span style="color: #007700">as </span><span style="color: #0000BB">$title</span><span style="color: #007700">) {<br />  echo </span><span style="color: #0000BB">$title </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Chapter 1
Chapter 2</pre>
</div>
    </div>
    <div class="example-contents"><p>
     Notez comment le document XML montré dans cet exemple fixe un espace de
     nom avec le préfixe <code class="literal">chap</code>. Imaginez que ce document (ou
     un autre similaire) puisse avoir utilisé un préfixe <code class="literal">c</code>
     dans le passé pour le même espace de noms. Puisqu&#039;il a changé, la requête
     XPath ne retournerait plus les résultats appropriés et la requête devrait
     être modifiée. L&#039;utilisation de <code class="literal">registerXPathNamespace</code>
     évite les modifications futures de la requête même si le fournisseur
     change le préfixe d&#039;espace de noms.
    </p></div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-simplexmlelement.registerxpathnamespace-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="simplexmlelement.xpath.php" class="methodname" rel="rdfs-seeAlso">SimpleXMLElement::xpath()</a> - Ex&eacute;cute une requ&ecirc;te Xpath sur des donn&eacute;es XML</span></li>
    <li><span class="methodname"><a href="simplexmlelement.getdocnamespaces.php" class="methodname" rel="rdfs-seeAlso">SimpleXMLElement::getDocNamespaces()</a> - Retourne les espaces de noms d&eacute;clar&eacute;s dans un document</span></li>
    <li><span class="methodname"><a href="simplexmlelement.getnamespaces.php" class="methodname" rel="rdfs-seeAlso">SimpleXMLElement::getNamespaces()</a> - Retourne les espaces de noms utilis&eacute;s dans un document</span></li>
   </ul>
  </p>
 </div>

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