[nycphp-talk] recursive simplexml
Matthew Terenzio
matt at jobsforge.com
Fri Mar 18 20:46:17 EST 2005
I want to recursively iterate over an OPML file. It can have any number
of 'outline' elements and each can have any number of children
'outline' elements.
As I move down the tree I'll handle each by looking at their 'type'
attribute.
here is an example snip of an OPML file:
<outline text="Top">
<outline text="About">
<outline text="Website" type="link" url="http://www.yahoo.com"/>
</outline>
<outline text="News">
<outline text="Today's" type='headline'>
and where my mind was headed...
$file = file_get_contents("thefile.opml");
$xml = new RecursiveIteratorIterator(new SimpleXMLIterator($file),
true);
foreach($xml as $element) {
if ($element == 'outline') {
if ($element[type] == 'link') {
SimonSays 'do this';
}
if ($element[type] == 'headline'{
SimonSays 'do that';
}
}
}
How far off am I?
More information about the talk
mailing list