File:
1.00.6a/server/base/node.xml.inc.php (
View as Code)
1: 2: /* -------------------------------------------------------------
3: This file is part of FreeNATS
4:
5: FreeNATS is (C) Copyright 2008 PurplePixie Systems
6:
7: FreeNATS is free software: you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation, either version 3 of the License, or
10: (at your option) any later version.
11:
12: FreeNATS is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with FreeNATS. If not, see www.gnu.org/licenses
19:
20: For more information see www.purplepixie.org/freenats
21: -------------------------------------------------------------- */
22:
23: class TNodeXML
24: {
25: var $Catalogue=array();
26: var $Init=false;
27: var $Elements=0;
28: var $Tests=0;
29: var $Header=array();
30: var $LastError="";
31:
32: var $in_freenats=false;
33: var $in_header=false;
34: var $in_test=false;
35: var $depth=0;
36: var $last_element="";
37: var $cur_testname="";
38:
39: function startElement($parser, $name, $attrs)
40: {
41: if ($name=="FREENATS-DATA") $this->in_freenats=true;
42: if (!$this->in_freenats) return 0;
43:
44: if ($name=="TEST")
45: {
46: $this->in_test=true;
47: $this->Tests++;
48: $this->cur_testname=$attrs['NAME'];
49: }
50: else if ($name=="HEADER") $in_header=true;
51: $this->last_element=$name;
52: $this->depth++;
53: $this->Elements++;
54: }
55:
56: function endElement($parser, $name)
57: {
58: $this->depth--;
59: if ($name=="TEST") $in_test=false;
60: else if ($name=="HEADER") $in_header=false;
61: else if ($name=="FREENATS-DATA") $in_freenats=false;
62: }
63:
64: function charData($parser,$data)
65: {
66: if (!$this->in_freenats) return 0;
67: $data=trim($data);
68: if ($data!="")
69: {
70: if ($this->in_test)
71: {
72: $this->Catalogue[$this->cur_testname][$this->last_element]=$data;
73: }
74: else if ($this->in_header)
75: $this->Header[$this->last_element]=$data;
76: }
77: }
78:
79: function Error()
80: {
81: return $this->LastError;
82: }
83:
84: function Parse($xml)
85: {
86: $this->Init=true;
87: $parser=xml_parser_create();
88: xml_set_element_handler($parser,Array( $this, "startElement" ),
89: Array( $this, "endElement" ) );
90: xml_set_character_data_handler($parser,Array( $this, "charData" ));
91:
92: $return=true;
93:
94: if (!xml_parse($parser,$xml,true))
95: {
96: $this->LastError="XML Error ".xml_error_string(xml_get_error_code($parser));
97: $this->LastError.=" at line ".xml_get_current_line_number($parser);
98: $return=false;
99: }
100:
101: xml_parser_free($parser);
102:
103: if ($return) return $this->Catalogue;
104: else return 0;
105: }
106:
107: function ParseFile($xmlfile)
108: {
109: $fp=fopen($xmlfile,"r")
110: or die("Could not open XML file ".$xmlfile);
111: $data="";
112: while (!feof($fp))
113: $data.=fgets($fp,4096);
114: fclose($fp);
115: return $this->Parse($data);
116: }
117:
118:
119: }
120: ?>