ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
XML.php
Go to the documentation of this file.
1<?php
2
33 function init($xml_string, $namespace_map)
34 {
35 if (!$this->setXML($xml_string)) {
36 return false;
37 }
38
39 foreach ($namespace_map as $prefix => $uri) {
40 if (!$this->registerNamespace($prefix, $uri)) {
41 return false;
42 }
43 }
44
45 return true;
46 }
47
61 function registerNamespace($prefix, $uri)
62 {
63 // Not implemented.
64 }
65
76 function setXML($xml_string)
77 {
78 // Not implemented.
79 }
80
94 function &evalXPath($xpath, $node = null)
95 {
96 // Not implemented.
97 }
98
107 function content($node)
108 {
109 // Not implemented.
110 }
111
121 function attributes($node)
122 {
123 // Not implemented.
124 }
125}
126
138 {
139 $this->xml = null;
140 $this->doc = null;
141 $this->xpath = null;
142 $this->errors = array();
143 }
144
145 function setXML($xml_string)
146 {
147 $this->xml = $xml_string;
148 $this->doc = @domxml_open_mem($xml_string, DOMXML_LOAD_PARSING,
149 $this->errors);
150
151 if (!$this->doc) {
152 return false;
153 }
154
155 $this->xpath = $this->doc->xpath_new_context();
156
157 return true;
158 }
159
160 function registerNamespace($prefix, $uri)
161 {
162 return xpath_register_ns($this->xpath, $prefix, $uri);
163 }
164
165 function &evalXPath($xpath, $node = null)
166 {
167 if ($node) {
168 $result = @$this->xpath->xpath_eval($xpath, $node);
169 } else {
170 $result = @$this->xpath->xpath_eval($xpath);
171 }
172
173 if (!$result) {
174 $n = array();
175 return $n;
176 }
177
178 if (!$result->nodeset) {
179 $n = array();
180 return $n;
181 }
182
183 return $result->nodeset;
184 }
185
186 function content($node)
187 {
188 if ($node) {
189 return $node->get_content();
190 }
191 }
192
193 function attributes($node)
194 {
195 if ($node) {
196 $arr = $node->attributes();
197 $result = array();
198
199 if ($arr) {
200 foreach ($arr as $attrnode) {
201 $result[$attrnode->name] = $attrnode->value;
202 }
203 }
204
205 return $result;
206 }
207 }
208}
209
220 function Auth_Yadis_dom()
221 {
222 $this->xml = null;
223 $this->doc = null;
224 $this->xpath = null;
225 $this->errors = array();
226 }
227
228 function setXML($xml_string)
229 {
230 $this->xml = $xml_string;
231 $this->doc = new DOMDocument;
232
233 if (!$this->doc) {
234 return false;
235 }
236
237 if (!@$this->doc->loadXML($xml_string)) {
238 return false;
239 }
240
241 $this->xpath = new DOMXPath($this->doc);
242
243 if ($this->xpath) {
244 return true;
245 } else {
246 return false;
247 }
248 }
249
250 function registerNamespace($prefix, $uri)
251 {
252 return $this->xpath->registerNamespace($prefix, $uri);
253 }
254
255 function &evalXPath($xpath, $node = null)
256 {
257 if ($node) {
258 $result = @$this->xpath->query($xpath, $node);
259 } else {
260 $result = @$this->xpath->query($xpath);
261 }
262
263 $n = array();
264
265 if (!$result) {
266 return $n;
267 }
268
269 for ($i = 0; $i < $result->length; $i++) {
270 $n[] = $result->item($i);
271 }
272
273 return $n;
274 }
275
276 function content($node)
277 {
278 if ($node) {
279 return $node->textContent;
280 }
281 }
282
283 function attributes($node)
284 {
285 if ($node) {
286 $arr = $node->attributes;
287 $result = array();
288
289 if ($arr) {
290 for ($i = 0; $i < $arr->length; $i++) {
291 $node = $arr->item($i);
292 $result[$node->nodeName] = $node->nodeValue;
293 }
294 }
295
296 return $result;
297 }
298 }
299}
300
303
314{
317}
318
320{
321 return array('dom' => 'Auth_Yadis_dom',
322 'domxml' => 'Auth_Yadis_domxml');
323}
324
332{
334
335 if (isset($__Auth_Yadis_defaultParser)) {
337 }
338
339 foreach(Auth_Yadis_getSupportedExtensions() as $extension => $classname)
340 {
341 if (extension_loaded($extension))
342 {
343 $p = new $classname();
345 return $p;
346 }
347 }
348
349 return false;
350}
351
352
$result
$n
Definition: RandomTest.php:80
Auth_Yadis_getSupportedExtensions()
Definition: XML.php:319
Auth_Yadis_getXMLParser()
Returns an instance of a Auth_Yadis_XMLParser subclass based on the availability of PHP extensions fo...
Definition: XML.php:331
global $__Auth_Yadis_defaultParser
Definition: XML.php:301
Auth_Yadis_setDefaultParser($parser)
Set a default parser to override the extension-driven selection of available parser classes.
Definition: XML.php:313
registerNamespace($prefix, $uri)
Register a namespace with the XML parser.
Definition: XML.php:61
setXML($xml_string)
Set this parser object's XML payload.
Definition: XML.php:76
attributes($node)
Return the attributes of a specified node.
Definition: XML.php:121
& evalXPath($xpath, $node=null)
Evaluate an XPath expression and return the resulting node list.
Definition: XML.php:94
init($xml_string, $namespace_map)
Initialize an instance of Auth_Yadis_XMLParser with some XML and namespaces.
Definition: XML.php:33
content($node)
Return the textual content of a specified node.
Definition: XML.php:107
Auth_Yadis_dom()
Definition: XML.php:220
setXML($xml_string)
Set this parser object's XML payload.
Definition: XML.php:228
& evalXPath($xpath, $node=null)
Evaluate an XPath expression and return the resulting node list.
Definition: XML.php:255
content($node)
Return the textual content of a specified node.
Definition: XML.php:276
attributes($node)
Return the attributes of a specified node.
Definition: XML.php:283
registerNamespace($prefix, $uri)
Register a namespace with the XML parser.
Definition: XML.php:250
setXML($xml_string)
Set this parser object's XML payload.
Definition: XML.php:145
attributes($node)
Return the attributes of a specified node.
Definition: XML.php:193
& evalXPath($xpath, $node=null)
Evaluate an XPath expression and return the resulting node list.
Definition: XML.php:165
registerNamespace($prefix, $uri)
Register a namespace with the XML parser.
Definition: XML.php:160
content($node)
Return the textual content of a specified node.
Definition: XML.php:186
Auth_Yadis_domxml()
Definition: XML.php:137
xpath_register_ns($xpath_context, $prefix, $namespaceURI)
const DOMXML_LOAD_PARSING
domxml_open_mem($str, $mode=DOMXML_LOAD_PARSING, &$error=NULL)