News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1240707422:v:use_geshi-1:v:type-php

Started by SleePy, Apr 26, 2009, 12:57 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

SleePy

// Recursive function for displaying generic XML data.
function template_mod_generic_xml_recursive($xml_data, $parent_ident, $child_ident, $old_level, $no_parent = false)
{
   // This is simply for neat indentation.
   $level = $old_level;
   if (!$no_parent)
      ++$level;

   if (!$no_parent)
      echo "\n" . str_repeat("\t", $old_level), '<', $parent_ident, '>';

   foreach ($xml_data as $key => $data)
   {
      // A group?
      if (is_array($data) && isset($data['children']) && (isset($data['identifier']) || isset($data['parent_identifier'])))
         template_mod_generic_xml_recursive($data['children'], isset($data['parent_identifier']) ? $data['parent_identifier'] : $key, $data['identifier'], $level, isset($data['no_parent']) ? true : false);
      // An item...
      elseif (is_array($data) && isset($data['value']))
      {
         if (!empty($data['identifier']))
            $index_key = $data['identifier'];
         else
            $index_key = $child_ident;

         echo "\n", str_repeat("\t", $level), '<', $index_key;

         if (!empty($data['attributes']))
            foreach ($data['attributes'] as $k => $v)
               echo ' ' . $k . '="' . $v . '"';
         echo '><![CDATA[', cleanXml($data['value']), ']]></', $index_key, '>';
      }
      else
         echo "\n", str_repeat("\t", $level), '<', $key, '><![CDATA[', cleanXml($data), ']]></', $key, '>';
   }

   if (!$no_parent)
      echo "\n", str_repeat("\t", $old_level), '</', $parent_ident, '>';
}
No siggy! :D