function ia2xml($array) { $xml = ""; foreach ($array as $key => $value) { if (is_array($value)) { $xml .= "<{$key}>" . ia2xml($value) . "</{$key}>"; } else { $xml .= "<{$key}>" . $value . "</{$key}>"; } } return $xml; }
public function getXml() { $this->xmlBody = ia2xml($this->bodyData); return $this->xmlHeader . $this->xmlBody . $this->xmlFooter; }
function ia2xml($array) { $xml = ""; foreach ($array as $key => $value) { $key_strings = explode(" ", $key); $keyEnd = $key; if (sizeof($key_strings) > 1) { $keyEnd = $key_strings[0]; } if (is_array($value)) { $array_keys = array_keys($value); $enterFlag = 1; foreach ($array_keys as $key_val) { if (!preg_match("/^[0-9]+\$/", $key_val)) { $enterFlag = 0; break; } } if ($enterFlag) { //多节点 foreach ($value as $val) { if (is_array($val)) { $xml .= "<{$key}>" . ia2xml($val) . "</{$keyEnd}>"; } else { $xml .= "<{$key}>{$val}</{$keyEnd}>"; } } } else { $xml .= "<{$key}>" . ia2xml($value) . "</{$keyEnd}>"; } } else { $xml .= "<{$key}>" . $value . "</{$keyEnd}>"; } } return $xml; }
function array2xml($array, $tag = 'template') { static $index = 1; $xml = "<{$tag}{$index}>\n" . ia2xml($array) . "</{$tag}{$index}>\n"; $index++; return $xml; }
function ia2xml($array, $subst) { $xml = ""; foreach ($array as $key => $value) { if (is_array($value)) { if (is_numeric($key)) { $xml .= "<" . $subst . "_" . $key . ">" . ia2xml($value, $subst) . "</" . $subst . "_" . $key . ">"; } else { $xml .= "<{$key}>" . ia2xml($value, $subst) . "</{$key}>"; } } else { /*$value = preg_replace("/&(?!amp;)/","&",$value); $value = str_replace("<","<",$value); $value = str_replace(">",">",$value); $value = str_replace("\"",""",$value); $value = str_replace("'","'",$value); $value = str_replace("%","%",$value);*/ $value = htmlspecialchars($value); if (is_numeric($key)) { $xml .= "<" . $subst . "_" . $key . ">" . $value . "</" . $subst . "_" . $key . ">"; } else { $xml .= "<{$key}>" . $value . "</{$key}>"; } } } return $xml; }