public function Index($rows) { $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="GBK"?><DOCUMENT/>'); foreach ($rows as $keys => $values) { foreach ($values as $key => $value) { $i = -8; $num_item = $xml->addchild($key); $num_key = $num_item->addchild('key'); $num_display = $num_item->addchild('display'); $n = 1; foreach ($value as $k => $val) { $n++; if ($n < 3) { $num_key->addCData($val); } else { $i++; if ($i < 14) { $num_display->{$k} = NULL; $num_display->{$k}->addCData($val); continue; } elseif ($i == 14) { $num_moremore = $num_display->addchild('moremore'); $num_moremore->{$k} = NULL; $num_moremore->{$k}->addCData($val); } $num_moremore->{$k} = NULL; $num_moremore->{$k}->addCData($val); } } } } echo $xml->asXml(); }