forked from alisonperez/chits
-
Notifications
You must be signed in to change notification settings - Fork 15
/
xmltest.php
executable file
·50 lines (44 loc) · 1.4 KB
/
xmltest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
class DataNode {
var $name; // node name
var $code; // three digit code
var $telephone; // node phone
var $level; // self, parent, child
function DataNode ($aa) {
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
function readConfig($filename) {
// read the xml database of aminoacids
$data = implode("",file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=>$val) {
if ($key == "node") {
$noderanges = $val;
// each contiguous pair of array entries are the
// lower and upper range for each node definition
for ($i=0; $i < count($noderanges); $i+=2) {
$offset = $noderanges[$i] + 1;
$len = $noderanges[$i + 1] - $offset;
$tdb[] = parseXML(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}
function parseXML($mvalues) {
for ($i=0; $i < count($mvalues); $i++)
$node[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
return new DataNode($node);
}
$db = readConfig("config.xml");
print_r($db);
?>