| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function GetChildren($vals, &$i) |
|---|
| 4 |
{ |
|---|
| 5 |
$children = array(); |
|---|
| 6 |
|
|---|
| 7 |
/* Node has CDATA before it's children */ |
|---|
| 8 |
if (isset($vals[$i]['value'])) |
|---|
| 9 |
$children['VALUE'] = $vals[$i]['value']; |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
while (++$i < count($vals)) |
|---|
| 13 |
{ |
|---|
| 14 |
switch ($vals[$i]['type']) |
|---|
| 15 |
{ |
|---|
| 16 |
|
|---|
| 17 |
(Add to cdata found before if this is the case) */ |
|---|
| 18 |
case 'cdata': |
|---|
| 19 |
if (isset($children['VALUE'])) |
|---|
| 20 |
$children['VALUE'] .= $vals[$i]['value']; |
|---|
| 21 |
else |
|---|
| 22 |
$children['VALUE'] = $vals[$i]['value']; |
|---|
| 23 |
break; |
|---|
| 24 |
|
|---|
| 25 |
case 'complete': |
|---|
| 26 |
if (isset($vals[$i]['attributes'])) { |
|---|
| 27 |
$children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes']; |
|---|
| 28 |
$index = count($children[$vals[$i]['tag']])-1; |
|---|
| 29 |
|
|---|
| 30 |
if (isset($vals[$i]['value'])) |
|---|
| 31 |
$children[$vals[$i]['tag']][$index]['VALUE'] = $vals[$i]['value']; |
|---|
| 32 |
else |
|---|
| 33 |
$children[$vals[$i]['tag']][$index]['VALUE'] = ''; |
|---|
| 34 |
} else { |
|---|
| 35 |
if (isset($vals[$i]['value'])) |
|---|
| 36 |
$children[$vals[$i]['tag']][]['VALUE'] = $vals[$i]['value']; |
|---|
| 37 |
else |
|---|
| 38 |
$children[$vals[$i]['tag']][]['VALUE'] = ''; |
|---|
| 39 |
} |
|---|
| 40 |
break; |
|---|
| 41 |
|
|---|
| 42 |
case 'open': |
|---|
| 43 |
if (isset($vals[$i]['attributes'])) { |
|---|
| 44 |
$children[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes']; |
|---|
| 45 |
$index = count($children[$vals[$i]['tag']])-1; |
|---|
| 46 |
$children[$vals[$i]['tag']][$index] = array_merge($children[$vals[$i]['tag']][$index],GetChildren($vals, $i)); |
|---|
| 47 |
} else { |
|---|
| 48 |
$children[$vals[$i]['tag']][] = GetChildren($vals, $i); |
|---|
| 49 |
} |
|---|
| 50 |
break; |
|---|
| 51 |
|
|---|
| 52 |
case 'close': |
|---|
| 53 |
return $children; |
|---|
| 54 |
} |
|---|
| 55 |
} |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
function GetXMLTreeProfile($xmlloc) |
|---|
| 60 |
{ |
|---|
| 61 |
if (file_exists($xmlloc)) { |
|---|
| 62 |
$data = implode('', file($xmlloc)); |
|---|
| 63 |
} else { |
|---|
| 64 |
$fp = fopen($xmlloc,'r'); |
|---|
| 65 |
$data = fread($fp, 100000000); |
|---|
| 66 |
fclose($fp); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
$data = preg_replace("/<knows>.*<\/knows>/is","",$data); |
|---|
| 70 |
|
|---|
| 71 |
$parser = xml_parser_create('UTF-8'); |
|---|
| 72 |
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); |
|---|
| 73 |
xml_parse_into_struct($parser, $data, $vals, $index); |
|---|
| 74 |
xml_parser_free($parser); |
|---|
| 75 |
$code = xml_get_error_code($parser); |
|---|
| 76 |
if ($code != XML_ERROR_NONE) { |
|---|
| 77 |
global $messages; |
|---|
| 78 |
$messages[] = __gettext("XML error: ") . xml_error_string($code); |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
$tree = array(); |
|---|
| 82 |
$i = 0; |
|---|
| 83 |
|
|---|
| 84 |
if (isset($vals[$i]['attributes'])) { |
|---|
| 85 |
$tree[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes']; |
|---|
| 86 |
$index = count($tree[$vals[$i]['tag']])-1; |
|---|
| 87 |
$tree[$vals[$i]['tag']][$index] = array_merge($tree[$vals[$i]['tag']][$index], GetChildren($vals, $i)); |
|---|
| 88 |
} else { |
|---|
| 89 |
$tree[$vals[$i]['tag']][] = GetChildren($vals, $i); |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
return $tree; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
function GetXMLTree($xmlloc) |
|---|
| 97 |
{ |
|---|
| 98 |
if (file_exists($xmlloc)) |
|---|
| 99 |
$data = implode('', file($xmlloc)); |
|---|
| 100 |
else { |
|---|
| 101 |
$fp = fopen($xmlloc,'r'); |
|---|
| 102 |
$data = fread($fp, 100000000); |
|---|
| 103 |
fclose($fp); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
$parser = xml_parser_create('UTF-8'); |
|---|
| 107 |
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); |
|---|
| 108 |
xml_parse_into_struct($parser, $data, $vals, $index); |
|---|
| 109 |
xml_parser_free($parser); |
|---|
| 110 |
|
|---|
| 111 |
$tree = array(); |
|---|
| 112 |
$i = 0; |
|---|
| 113 |
|
|---|
| 114 |
if (isset($vals[$i]['attributes'])) { |
|---|
| 115 |
$tree[$vals[$i]['tag']][]['ATTRIBUTES'] = $vals[$i]['attributes']; |
|---|
| 116 |
$index = count($tree[$vals[$i]['tag']])-1; |
|---|
| 117 |
$tree[$vals[$i]['tag']][$index] = array_merge($tree[$vals[$i]['tag']][$index], GetChildren($vals, $i)); |
|---|
| 118 |
} |
|---|
| 119 |
else |
|---|
| 120 |
$tree[$vals[$i]['tag']][] = GetChildren($vals, $i); |
|---|
| 121 |
|
|---|
| 122 |
return $tree; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
?> |
|---|