/** * 数组解析成XML * @return string * @author Kevin */ function array_to_xml($packet, $tags = '', $pre = '') { if (is_array($packet)) { $xml = ''; foreach ($packet as $key => $value) { $titlekey = ucfirst($key); $xml .= creat_amango_tag($tags[$titlekey]['head'], $pre) . "<{$titlekey}><![CDATA[" . creat_amango_tag($tags[$titlekey]['_before'], $pre) . $value . creat_amango_tag($tags[$titlekey]['after_'], $pre) . "]]></{$titlekey}>" . creat_amango_tag($tags[$titlekey]['end'], $pre); } return $xml; } else { return null; } }
public function select() { self::parax_tags($this->options['tags']); //$data = $this->data; //$group = $this->_group; //$top = $this->_top; if ($this->_level && self::judgeData($this->data)) { //单项GROUP循环 $msgnums = count($this->data) - 1; $xml = ''; //子项标识 foreach ($this->_group as $key => $value) { for ($i = 0; $i <= $msgnums; $i++) { $head = creat_amango_tag($value['head'], $i) . '<' . $key . '>'; $end = '</' . $key . '>' . creat_amango_tag($value['end'], $i); $xml .= $head . array_to_xml($this->data[$i], $this->_tags, $i) . $end; } } } else { $xml = self::createItem($this->_tags); } //头部包裹 if (!empty($this->_top)) { foreach ($this->_top as $key => $value) { $tophead = '<' . $key . '>' . creat_amango_tag($value['head']); $topend = creat_amango_tag($value['end']) . '</' . $key . '>'; } $xml = $tophead . $xml . $topend; } return $xml; }