Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a191144584
Fetching contributors…

Cannot retrieve contributors at this time

file 31 lines (27 sloc) 0.786 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
<?php
function iterateXML()
{
    $siteXMLString = <<<ENDXML
<?xml version="1.0" encoding="UTF-8"?>
<site>
    <page name="projects">
        <page name="Project 1" />
        <page name="Project 2" />
    </page>
</site>

ENDXML;

    $iterator = new SimpleXMLIterator($siteXMLString);
    $projectsIterator = $iterator->xpath("//page");

    // Iterate through all 3 occurances of <page> elements
    foreach ($projectsIterator as $pageXML)
    {
        // Set a breakpoint somewhere inside this loop.
        // You won't see any variables in the Local Variables panel until the second
        // time through the loop. After that, they seem to work fine.
        $currentPageXML= $pageXML;
        $name = $currentPageXML["name"];
        echo $name . '
';
    }
}

iterateXML();
Something went wrong with that request. Please try again.