Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>SimpleXMLElement</code> is not so straightforward and in fact it gets <em>simple</em> only when you <em>guess</em> how to deal with it... or someone suggests you.</p> <p>Suppose <code>regions.xml</code> is like this:</p> <pre><code>&lt;regions&gt; &lt;region id="01" size="big"&gt; New Zealand &lt;/region&gt; &lt;region id="02" size="small"&gt; Tokelau &lt;/region&gt; &lt;/regions&gt; </code></pre> <p>The following PHP code can navigate through that XML document:</p> <pre><code>$xml = new SimpleXMLElement('regions.xml'); foreach ($xml-&gt;region as $region) { // iterate through all the regions echo 'Region ID: '. (string)$region['id']; // get the attribute id echo 'Region size: '. (string)$region['size']; // get the attribute size echo 'Region name: '. (string)$region; // get the contents of the // element by casting it to a string } </code></pre> <p>Now let's make something a bit harder... Suppose <code>&lt;region&gt;</code> has a subelement, <code>&lt;subregion&gt;</code>.</p> <pre><code>&lt;regions&gt; &lt;region id="01" size="big"&gt; &lt;name&gt;USA&lt;/name&gt; &lt;subregion id="01_1"&gt;Alaska&lt;/subregion&gt; &lt;/region&gt; ... &lt;/regions&gt; </code></pre> <p>If you want to get all the subregions for each region, you have to do like this:</p> <pre><code>$xml = new SimpleXMLElement('regions.xml'); foreach ($xml-&gt;region as $region) { // iterate through all the regions foreach ($region-&gt;subregion as $subregion) // iterate trough the subregion of $region // do something } } </code></pre> <p>Your document structure seems a bit more complex than this, but using these basics you can easily work it out.</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. This table or related slice is empty.
    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