Example #1
0
 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;
 }
Example #2
0
 public function getXml()
 {
     $this->xmlBody = ia2xml($this->bodyData);
     return $this->xmlHeader . $this->xmlBody . $this->xmlFooter;
 }
Example #3
0
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;
}
Example #4
0
function array2xml($array, $tag = 'template')
{
    static $index = 1;
    $xml = "<{$tag}{$index}>\n" . ia2xml($array) . "</{$tag}{$index}>\n";
    $index++;
    return $xml;
}
Example #5
0
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;)/","&amp;",$value);
            		$value = str_replace("<","&lt;",$value);
            		$value = str_replace(">","&gt;",$value);
            		$value = str_replace("\"","&quot;",$value);
            		$value = str_replace("'","&apos;",$value);
            		$value = str_replace("%","&#37;",$value);*/
            $value = htmlspecialchars($value);
            if (is_numeric($key)) {
                $xml .= "<" . $subst . "_" . $key . ">" . $value . "</" . $subst . "_" . $key . ">";
            } else {
                $xml .= "<{$key}>" . $value . "</{$key}>";
            }
        }
    }
    return $xml;
}