-
More SimpleXML to display OPML
jake on 2010.04.22
at 05:28 pmMatt Katz recently sent in an email regarding the code we use to display our OPML lists. He needed a second pair of eyes to go over his new class. Turned out the bug wasn’t in his display function but the once over highlighted some other issues with ours.
The pages here are now updated but we can’t keep this all to ourselves. Here’s the updated code for traversing an OPML file.
function displayChildrenRecursive($xmlObj,$depth=1) { $outPut = ""; if (count($xmlObj->children()) > 0) { $outPut .= str_repeat("\t",$depth).'<ul class="opmlGroup">'."\n"; } foreach($xmlObj->children() as $child) { if (isset($child['htmlUrl']) || isset($child['xmlUrl'])) { $outPut .= str_repeat("\t",$depth).'<li>'; if (isset($child['htmlUrl'])) { $outPut .= '<a href="'.htmlentities($child['htmlUrl']).'"'; $outPut .= (isset($child['description'])) ? ' title="'.htmlentities($child['description']).'"' : ''; $outPut .= '>'.$child['text'].'</a>'; } else { $outPut .= $child['text']; } $outPut .= (isset($child['xmlUrl'])) ? ' [<a href="'.htmlentities($child['xmlUrl']).'">XML Feed</a>]' : ''; $outPut .= '</li>'."\n"; } elseif (isset($child['text']) && !isset($child['xmlUrl'])) { $outPut .= str_repeat("\t",$depth).'<li><h'.($depth+1).'>'.$child['text'].'</h'.($depth+1).'>'."\n"; } $outPut .= displayChildrenRecursive($child,$depth+1); }if (count($xmlObj->children()) > 0) { $outPut .= str_repeat("\t",$depth).'</ul>'."\n"; if ($depth > 1) { $outPut .= str_repeat("\t",$depth-1).'</li>'."\n"; } } return $outPut; }Posted in: Web · Programming

Comments (0)
Comments have been automatically disabled to curtail spam.
