<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/simplexml.examples.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'simplexml.examples-basic.php',
    1 => 'Basic SimpleXML usage',
    2 => 'Basic SimpleXML usage',
  ),
  'up' => 
  array (
    0 => 'simplexml.examples.php',
    1 => 'Приклади',
  ),
  'prev' => 
  array (
    0 => 'simplexml.examples.php',
    1 => 'Приклади',
  ),
  'next' => 
  array (
    0 => 'simplexml.examples-errors.php',
    1 => 'Dealing with XML errors',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/simplexml/examples.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="simplexml.examples-basic" class="section">
  <h2 class="title">Basic SimpleXML usage</h2>
  <p class="para">
   Many examples in this reference require an XML string. Instead of
   repeating this string in every example, we put it into a file which
   we include in each example. This included file is shown in the 
   following example section. Alternatively, you could create an XML
   document and read it with <span class="function"><a href="function.simplexml-load-file.php" class="function">simplexml_load_file()</a></span>.
  </p>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Include file examples/simplexml-data.php with XML string</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$xmlstr </span><span style="color: #007700">= &lt;&lt;&lt;XML<br /></span><span style="color: #DD0000">&lt;?xml version='1.0' standalone='yes'?&gt;<br />&lt;movies&gt;<br /> &lt;movie&gt;<br />  &lt;title&gt;PHP: Behind the Parser&lt;/title&gt;<br />  &lt;characters&gt;<br />   &lt;character&gt;<br />    &lt;name&gt;Ms. Coder&lt;/name&gt;<br />    &lt;actor&gt;Onlivia Actora&lt;/actor&gt;<br />   &lt;/character&gt;<br />   &lt;character&gt;<br />    &lt;name&gt;Mr. Coder&lt;/name&gt;<br />    &lt;actor&gt;El Act&amp;#211;r&lt;/actor&gt;<br />   &lt;/character&gt;<br />  &lt;/characters&gt;<br />  &lt;plot&gt;<br />   So, this language. It's like, a programming language. Or is it a<br />   scripting language? All is revealed in this thrilling horror spoof<br />   of a documentary.<br />  &lt;/plot&gt;<br />  &lt;great-lines&gt;<br />   &lt;line&gt;PHP solves all my web problems&lt;/line&gt;<br />  &lt;/great-lines&gt;<br />  &lt;rating type="thumbs"&gt;7&lt;/rating&gt;<br />  &lt;rating type="stars"&gt;5&lt;/rating&gt;<br /> &lt;/movie&gt;<br />&lt;/movies&gt;<br /></span><span style="color: #007700">XML;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   The simplicity of SimpleXML appears most clearly when one extracts
   a string or number from a basic XML document.
   <div class="example" id="example-2">
    <p><strong>Приклад #2 Getting <code class="literal">&lt;plot&gt;</code></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">plot</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>

   So, this language. It&#039;s like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.

</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   Accessing elements within an XML document that contain characters not permitted under 
   PHP&#039;s naming convention (e.g. the hyphen) can be accomplished by encapsulating the
   element name within braces and the apostrophe.
   <div class="example" id="example-3">
    <p><strong>Приклад #3 Getting <code class="literal">&lt;line&gt;</code></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">-&gt;{</span><span style="color: #DD0000">'great-lines'</span><span style="color: #007700">}-&gt;</span><span style="color: #0000BB">line</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
PHP solves all my web problems
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4">
    <p><strong>Приклад #4 Accessing non-unique elements in SimpleXML</strong></p>
    <div class="example-contents"><p>
     When multiple instances of an element exist as children of
     a single parent element, normal iteration techniques apply.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* For each &lt;character&gt; node, we echo a separate &lt;name&gt;. */<br /></span><span style="color: #007700">foreach (</span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">characters</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">character </span><span style="color: #007700">as </span><span style="color: #0000BB">$character</span><span style="color: #007700">) {<br />   echo </span><span style="color: #0000BB">$character</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">, </span><span style="color: #DD0000">' played by '</span><span style="color: #007700">, </span><span style="color: #0000BB">$character</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">actor</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
</pre></div>
    </div>
   </div>
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    Properties (<code class="literal">$movies-&gt;movie</code> in previous example) are not
    arrays. They are <a href="class.iterator.php" class="link">iterable</a> and
    <a href="class.arrayaccess.php" class="link">accessible</a> objects.
   </p>
  </p></blockquote>
  <p class="para">
   <div class="example" id="example-5">
    <p><strong>Приклад #5 Using attributes</strong></p>
    <div class="example-contents"><p>
     So far, we have only covered the work of reading element names
     and their values. SimpleXML can also access element attributes.
     Access attributes of an element just as you would elements
     of an <span class="type"><a href="language.types.array.php" class="type array">array</a></span>.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Access the &lt;rating&gt; nodes of the first movie.<br /> * Output the rating scale, too. */<br /></span><span style="color: #007700">foreach (</span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">rating </span><span style="color: #007700">as </span><span style="color: #0000BB">$rating</span><span style="color: #007700">) {<br />    switch((string) </span><span style="color: #0000BB">$rating</span><span style="color: #007700">[</span><span style="color: #DD0000">'type'</span><span style="color: #007700">]) { </span><span style="color: #FF8000">// Get attributes as element indices<br />    </span><span style="color: #007700">case </span><span style="color: #DD0000">'thumbs'</span><span style="color: #007700">:<br />        echo </span><span style="color: #0000BB">$rating</span><span style="color: #007700">, </span><span style="color: #DD0000">' thumbs up'</span><span style="color: #007700">;<br />        break;<br />    case </span><span style="color: #DD0000">'stars'</span><span style="color: #007700">:<br />        echo </span><span style="color: #0000BB">$rating</span><span style="color: #007700">, </span><span style="color: #DD0000">' stars'</span><span style="color: #007700">;<br />        break;<br />    }<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
7 thumbs up5 stars
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-6">
    <p><strong>Приклад #6 Comparing Elements and Attributes with Text</strong></p>
    <div class="example-contents"><p>
     To compare an element or attribute with a string or pass it into a 
     function that requires a string, you must cast it to a string using 
     <code class="literal">(string)</code>. Otherwise, PHP treats the element as an object.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br />if ((string) </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">title </span><span style="color: #007700">== </span><span style="color: #DD0000">'PHP: Behind the Parser'</span><span style="color: #007700">) {<br />    print </span><span style="color: #DD0000">'My favorite movie.'</span><span style="color: #007700">;<br />}<br /><br />echo </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">((string) </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">title</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
My favorite movie.PHP: Behind the Parser
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-7">
    <p><strong>Приклад #7 Comparing Two Elements</strong></p>
    <div class="example-contents"><p>
     Two SimpleXMLElements are considered different even if they point to the
     same element.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$movies1 </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$movies2 </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$movies1 </span><span style="color: #007700">== </span><span style="color: #0000BB">$movies2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
bool(false)
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-8">
    <p><strong>Приклад #8 Using XPath</strong></p>
    <div class="example-contents"><p>
     SimpleXML includes built-in <abbr title="XML Path Language">XPath</abbr> support.
     To find all <code class="literal">&lt;character&gt;</code> elements.
    </p></div>
    <div class="example-contents"><p>
     &#039;<code class="literal">//</code>&#039; serves as a wildcard. To specify absolute
     paths, omit one of the slashes:
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">xpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'//character'</span><span style="color: #007700">) as </span><span style="color: #0000BB">$character</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$character</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">, </span><span style="color: #DD0000">' played by '</span><span style="color: #007700">, </span><span style="color: #0000BB">$character</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">actor</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-9">
    <p><strong>Приклад #9 Setting values</strong></p>
    <div class="example-contents"><p>
     Data in SimpleXML doesn&#039;t have to be constant. The object allows
     for manipulation of all of its elements.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">characters</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">character</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">name </span><span style="color: #007700">= </span><span style="color: #DD0000">'Miss Coder'</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">asXML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
&lt;?xml version=&quot;1.0&quot; standalone=&quot;yes&quot;?&gt;
&lt;movies&gt;
 &lt;movie&gt;
  &lt;title&gt;PHP: Behind the Parser&lt;/title&gt;
  &lt;characters&gt;
   &lt;character&gt;
    &lt;name&gt;Miss Coder&lt;/name&gt;
    &lt;actor&gt;Onlivia Actora&lt;/actor&gt;
   &lt;/character&gt;
   &lt;character&gt;
    &lt;name&gt;Mr. Coder&lt;/name&gt;
    &lt;actor&gt;El Act&amp;#xD3;r&lt;/actor&gt;
   &lt;/character&gt;
  &lt;/characters&gt;
  &lt;plot&gt;
   So, this language. It&#039;s like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  &lt;/plot&gt;
  &lt;great-lines&gt;
   &lt;line&gt;PHP solves all my web problems&lt;/line&gt;
  &lt;/great-lines&gt;
  &lt;rating type=&quot;thumbs&quot;&gt;7&lt;/rating&gt;
  &lt;rating type=&quot;stars&quot;&gt;5&lt;/rating&gt;
 &lt;/movie&gt;
&lt;/movies&gt;
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-10">
    <p><strong>Приклад #10 Adding elements and attributes</strong></p>
    <div class="example-contents"><p>
     SimpleXML has had the ability to easily add children and
     attributes.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'examples/simplexml-data.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= new </span><span style="color: #0000BB">SimpleXMLElement</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$character </span><span style="color: #007700">= </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">characters</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addChild</span><span style="color: #007700">(</span><span style="color: #DD0000">'character'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$character</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addChild</span><span style="color: #007700">(</span><span style="color: #DD0000">'name'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Mr. Parser'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$character</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addChild</span><span style="color: #007700">(</span><span style="color: #DD0000">'actor'</span><span style="color: #007700">, </span><span style="color: #DD0000">'John Doe'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$rating </span><span style="color: #007700">= </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">addChild</span><span style="color: #007700">(</span><span style="color: #DD0000">'rating'</span><span style="color: #007700">, </span><span style="color: #DD0000">'PG'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rating</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addAttribute</span><span style="color: #007700">(</span><span style="color: #DD0000">'type'</span><span style="color: #007700">, </span><span style="color: #DD0000">'mpaa'</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">asXML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
&lt;?xml version=&quot;1.0&quot; standalone=&quot;yes&quot;?&gt;
&lt;movies&gt;
 &lt;movie&gt;
  &lt;title&gt;PHP: Behind the Parser&lt;/title&gt;
  &lt;characters&gt;
   &lt;character&gt;
    &lt;name&gt;Ms. Coder&lt;/name&gt;
    &lt;actor&gt;Onlivia Actora&lt;/actor&gt;
   &lt;/character&gt;
   &lt;character&gt;
    &lt;name&gt;Mr. Coder&lt;/name&gt;
    &lt;actor&gt;El Act&amp;#xD3;r&lt;/actor&gt;
   &lt;/character&gt;
  &lt;character&gt;&lt;name&gt;Mr. Parser&lt;/name&gt;&lt;actor&gt;John Doe&lt;/actor&gt;&lt;/character&gt;&lt;/characters&gt;
  &lt;plot&gt;
   So, this language. It&#039;s like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  &lt;/plot&gt;
  &lt;great-lines&gt;
   &lt;line&gt;PHP solves all my web problems&lt;/line&gt;
  &lt;/great-lines&gt;
  &lt;rating type=&quot;thumbs&quot;&gt;7&lt;/rating&gt;
  &lt;rating type=&quot;stars&quot;&gt;5&lt;/rating&gt;
 &lt;rating type=&quot;mpaa&quot;&gt;PG&lt;/rating&gt;&lt;/movie&gt;
&lt;/movies&gt;
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-11">
    <p><strong>Приклад #11 DOM Interoperability</strong></p>
    <div class="example-contents"><p>
     PHP has a mechanism to convert XML nodes between SimpleXML
     and DOM formats. This example shows how one might change
     a DOM element to SimpleXML.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$dom </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;books&gt;&lt;book&gt;&lt;title&gt;blah&lt;/title&gt;&lt;/book&gt;&lt;/books&gt;'</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$dom</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">'Error while parsing the document'</span><span style="color: #007700">;<br />    exit;<br />}<br /><br /></span><span style="color: #0000BB">$books </span><span style="color: #007700">= </span><span style="color: #0000BB">simplexml_import_dom</span><span style="color: #007700">(</span><span style="color: #0000BB">$dom</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">$books</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">book</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">title</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive cdata"><pre>
blah
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-12">
    <p><strong>Приклад #12 Working with namespaces</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$data </span><span style="color: #007700">= &lt;&lt;&lt;XML<br /></span><span style="color: #DD0000">&lt;movies xmlns="http://default" xmlns:a="http://a"&gt;<br /> &lt;movie xml:id="movie1" a:link="IMDB"&gt;<br />  &lt;a:actor&gt;Onlivia Actora&lt;/a:actor&gt;<br /> &lt;/movie&gt;<br />&lt;/movies&gt;<br /></span><span style="color: #007700">XML;<br /><br /></span><span style="color: #0000BB">$movies </span><span style="color: #007700">= </span><span style="color: #0000BB">simplexml_load_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Namespace http://www.w3.org/XML/1998/namespace is available as "xml".<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">attributes</span><span style="color: #007700">(</span><span style="color: #DD0000">"xml"</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">)[</span><span style="color: #DD0000">"id"</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Namespaced attributes can be accessed with attributes().<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">attributes</span><span style="color: #007700">(</span><span style="color: #DD0000">"a"</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">)[</span><span style="color: #DD0000">"link"</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Using namespace URI allows document to use any namespace alias.<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">attributes</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://a"</span><span style="color: #007700">)[</span><span style="color: #DD0000">"link"</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Children can be accessed with children().<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">movie</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">children</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://a"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">actor </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Using xpath() with namespace requires registering it first.<br /></span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerXPathNamespace</span><span style="color: #007700">(</span><span style="color: #DD0000">"a"</span><span style="color: #007700">, </span><span style="color: #DD0000">"http://a"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">xpath</span><span style="color: #007700">(</span><span style="color: #DD0000">"//a:actor"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Even the default namespace must be registered.<br /></span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerXPathNamespace</span><span style="color: #007700">(</span><span style="color: #DD0000">"default"</span><span style="color: #007700">, </span><span style="color: #DD0000">"http://default"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">xpath</span><span style="color: #007700">(</span><span style="color: #DD0000">"//default:movie"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// This is empty.<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$movies</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">xpath</span><span style="color: #007700">(</span><span style="color: #DD0000">"//movie"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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