PHP generates XML code class Xmlparser {
function GetChildren ($vals, & $i) {
$children = Array ();
if (Isset ($vals [$i] [' value '])) {
$children [' value '] = $vals [$i] [' value '];
}
while (+ + $i < count ($vals)) {
Switch ($vals [$i] [' type ']) {
Case ' CDATA ':
if (Isset ($children [' VALUE ')]) {
$children [' value ']. = $vals [$i] [' value '];
} else {
$children [' value '] = $vals [$i] [' value '];
}
Break
Case ' complete ':
if (Isset ($vals [$i] [' attributes ']) {
$children [$vals [$i] [' tag ']][][' ATTRIBUTES '] = $vals [$i] [' ATTRIBUTES '];
$index = count ($children [$vals [$i] [' tag ']]-1;
if (Isset ($vals [$i] [' value '])) {
$children [$vals [$i] [' tag ']][$index] [' value '] = $vals [$i] [' value '];
} else {
$children [$vals [$i] [' tag ']][$index] [' VALUE '] = ';
}
} else {
if (Isset ($vals [$i] [' value '])) {
$children [$vals [$i] [' tag ']][][' value '] = $vals [$i] [' value '];
} else {
$children [$vals [$i] [' tag ']][][' VALUE '] = ';
}
}
Break
Case ' open ':
if (Isset ($vals [$i] [' attributes ']) {
$children [$vals [$i] [' tag ']][][' ATTRIBUTES '] = $vals [$i] [' ATTRIBUTES '];
$index = count ($children [$vals [$i] [' tag ']]-1;
$children [$vals [$i] [' tag ']][$index] = Array_merge ($children [$vals [$i] [' tag ']][$index], $this->getchildren ($ Vals, $i));
} else {
$children [$vals [$i] [' tag ']][] = $this->getchildren ($vals, $i);
}
Break
Case ' close ':
return $children;
}
}
}
function Getxmltree ($data) {
$parser = xml_parser_create (' UTF-8 ');
Xml_parser_set_option ($parser, xml_option_skip_white, 0);
Xml_parser_set_option ($parser, xml_option_case_folding, 0);
Xml_parse_into_struct ($parser, $data, $vals, $index);
Xml_parser_free ($parser);
$tree = Array ();
$i = 0;
if (Isset ($vals [$i] [' attributes ']) {
$tree [$vals [$i] [' tag ']][][' ATTRIBUTES '] = $vals [$i] [' ATTRIBUTES '];
$index = count ($tree [$vals [$i] [' tag ']]-1;
$tree [$vals [$i] [' tag ']][$index] = Array_merge ($tree [$vals [$i] [' tag ']][$index], $this->getchildren ($vals, $i));
} else {
$tree [$vals [$i] [' tag ']][] = $this->getchildren ($vals, $i);
}
return $tree;
}
}
http://www.bkjia.com/PHPjc/632011.html www.bkjia.com true http://www.bkjia.com/PHPjc/632011.html techarticle PHP generates XML code class Xmlparser {function GetChildren ($vals, $i) {$children = array (); if (Isset ($vals [$i] [' value ']) {$c hildren[' value ' = $vals [$i] [' value ']; } while (+ + $i Co ...