File:
1.17.2a/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: /* Modified 24/08/2009 for Added Debugging - may want to remove from
24: main release dependent on performance impact */
25:
26: /* Modified again 25/08/2009 - def don't want these mods included in
27: the main release */
28:
29: class TNodeXML
30: {
31: var $Catalogue=array();
32: var $Init=false;
33: var $Elements=0;
34: var $Tests=0;
35: var $Header=array();
36: var $LastError="";
37:
38: var $in_freenats=false;
39: var $in_header=false;
40: var $in_test=false;
41: var $depth=0;
42: var $last_element="";
43: var $cur_testname="";
44:
45: var $debug_log=false; //disabled but keep in for the moment
46:
47: function startElement($parser, $name, $attrs)
48: {
49: global $NATS;
50: if ($this->debug_log)
51: $NATS->Event("Start Element: ".$name,10,"NodeXML","StartE");
52: if ($name=="FREENATS-DATA")
53: {
54: $this->in_freenats=true;
55: if ($this->debug_log)
56: $NATS->Event("in_freenats set to true",10,"NodeXML","StartE");
57: }
58: if (!$this->in_freenats) return 0;
59:
60: if ($this->debug_log)
61: $NATS->Event("startE passed in_freenats true",10,"NodeXML","StartE");
62:
63: if ($name=="TEST")
64: {
65: $this->in_test=true;
66: $this->Tests++;
67: $this->cur_testname=$attrs['NAME'];
68: if ($this->debug_log)
69: $NATS->Event("Test Element: ".$this->cur_testname,10,"NodeXML","TestE");
70: }
71: else if ($name=="HEADER") $in_header=true;
72: $this->last_element=$name;
73: $this->depth++;
74: $this->Elements++;
75: }
76:
77: function endElement($parser, $name)
78: {
79: global $NATS;
80: $this->depth--;
81: if ($name=="TEST") $in_test=false;
82: else if ($name=="HEADER") $in_header=false;
83: else if ($name=="FREENATS-DATA")
84: {
85: $in_freenats=false;
86: if ($this->debug_log)
87: $NATS->Event("endE in_freenats set to false",10,"NodeXML","EndE");
88: }
89: if ($this->debug_log)
90: $NATS->Event("End Element: ".$name,10,"NodeXML","EndE");
91: }
92:
93: function charData($parser,$data)
94: {
95: global $NATS;
96: if ($this->debug_log) $NATS->Event("Char Data Called",10,"NodeXML","CharData");
97: if (!$this->in_freenats)
98: {
99: if ($this->debug_log)
100: $NATS->Event("Char Data in_freenats FALSE",10,"NodeXML","CharData");
101: return 0;
102: }
103: if ($this->debug_log)
104: {
105: $NATS->Event("Char Data in FreeNATS",10,"NodeXML","CharData");
106: $NATS->Event("Untrimmed Data: ".$data,10,"NodeXML","CharData");
107: }
108:
109: $data=trim($data);
110: if ($data!="")
111: {
112: if ($this->debug_log)
113: $NATS->Event("Data: ".$data,10,"NodeXML","CharData");
114:
115: if ($this->in_test)
116: {
117: $this->Catalogue[$this->cur_testname][$this->last_element]=$data;
118: }
119: else if ($this->in_header)
120: $this->Header[$this->last_element]=$data;
121: }
122: }
123:
124: function Error()
125: {
126: return $this->LastError;
127: }
128:
129: function Parse($xml)
130: {
131: if (get_magic_quotes_gpc()) $xml=stripslashes($xml);
132: $this->Init=true;
133: $parser=xml_parser_create();
134: xml_set_element_handler($parser,Array( $this, "startElement" ),
135: Array( $this, "endElement" ) );
136: xml_set_character_data_handler($parser,Array( $this, "charData" ));
137:
138: $return=true;
139:
140: if (!xml_parse($parser,$xml,true))
141: {
142: $this->LastError="XML Error ".xml_error_string(xml_get_error_code($parser));
143: $this->LastError.=" at line ".xml_get_current_line_number($parser);
144: if ($debug_log) $NATS->Event($this->LastError,5,"NodeXML","Parse");
145: $return=false;
146: }
147:
148: xml_parser_free($parser);
149:
150: if ($return) return $this->Catalogue;
151: else return 0;
152: }
153:
154: function ParseFile($xmlfile)
155: {
156: $fp=fopen($xmlfile,"r")
157: or die("Could not open XML file ".$xmlfile);
158: $data="";
159: while (!feof($fp))
160: $data.=fgets($fp,4096);
161: fclose($fp);
162: return $this->Parse($data);
163: }
164:
165:
166: }
167: ?>