ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
domxml-php4-php5.php
Go to the documentation of this file.
1 <?php
37  // new
38  function domxml_new_doc($version)
39  {
40 echo "-1";
41  return new php4DOMDocument('');
42  }
43 
44  // same
46  {
47 echo "-2";
48  return new php4DOMDocument($filename);
49  }
50 
51  // different
52  function domxml_open_mem($str)
53  {
54 echo "-3";
55  $dom=new php4DOMDocument('');
56  $dom->myDOMNode->loadXML($str);
57  return $dom;
58  }
59 
60  // different -> adapted in ilias
61  function xpath_eval($xpath_context,$eval_str,$contextnode=null)
62  {
63 echo "-4";
64  return $xpath_context->query($eval_str,$contextnode);
65  }
66 
67  // same
68  function xpath_new_context($dom_document)
69  {
70 echo "-5";
71  return new php4DOMXPath($dom_document);
72  }
73 
74 // same (nearly)
75 class php4DOMAttr extends php4DOMNode
76 {
77  function php4DOMAttr($aDOMAttr) {
78 echo "-6";
79  $this->myDOMNode=$aDOMAttr;
80  }
81 
82  function Name() {
83 echo "-7";
84  return $this->myDOMNode->name;
85  }
86 
87  function Specified() {
88 echo "-8";
89  return $this->myDOMNode->specified;
90  }
91 
92  function Value() {
93 echo "-9";
94  return $this->myDOMNode->value;
95  }
96 }
97 
98 // different
99 class php4DOMDocument extends php4DOMNode
100 {
101  // different
103  {
104 echo "-A";
105  $this->myDOMNode=new DOMDocument();
106  if ($filename!='') $this->myDOMNode->load($filename);
107  }
108 
109  // different (a little)
110  function create_attribute($name,$value)
111  {
112 echo "-B";
113  $myAttr=$this->myDOMNode->createAttribute($name);
114  $myAttr->value=$value;
115  return new php4DOMAttr($myAttr,$this);
116  }
117 
118  // different (little)
119  function create_cdata_section($content)
120  {
121 echo "-C";
122  return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);
123  }
124 
125  // different (little)
127  {
128 echo "-D";
129  return new php4DOMNode($this->myDOMNode->createComment($data),$this);
130  }
131 
132  // different (little)
133  function create_element($name)
134  {
135 echo "-E";
136  return new php4DOMElement($this->myDOMNode->createElement($name),$this);
137  }
138 
139  function create_text_node($content)
140  {
141 echo "-F";
142  return new php4DOMNode($this->myDOMNode->createTextNode($content),$this);
143  }
144 
145  function document_element()
146  {
147 echo "-G";
148  return new php4DOMElement($this->myDOMNode->documentElement,$this);
149  }
150 
151  function dump_file($filename,$compressionmode=false,$format=false)
152  {
153 echo "-H";
154  return $this->myDOMNode->save($filename);
155  }
156 
157  function dump_mem($format=false,$encoding=false)
158  {
159 echo "-I";
160  return $this->myDOMNode->saveXML();
161  }
162 
163  function get_element_by_id($id)
164  {
165 echo "-J";
166  return new php4DOMElement($this->myDOMNode->getElementById($id),$this);
167  }
168 
169  function get_elements_by_tagname($name)
170  {
171 echo "-K";
172  $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
173  $nodeSet=array();
174  $i=0;
175  if (isset($myDOMNodeList))
176  while ($node=$myDOMNodeList->item($i))
177  {
178  $nodeSet[]=new php4DOMElement($node,$this);
179  $i++;
180  }
181  return $nodeSet;
182  }
183 
184  function html_dump_mem()
185  {
186 echo "-L";
187  return $this->myDOMNode->saveHTML();
188  }
189 
190  function root()
191  {
192 echo "-M";
193  return new php4DOMElement($this->myDOMNode->documentElement,$this);
194  }
195 }
196 
197 class php4DOMElement extends php4DOMNode
198 {
199  function get_attribute($name)
200  {
201 echo "-N";
202  return $this->myDOMNode->getAttribute($name);
203  }
204 
205  function get_elements_by_tagname($name)
206  {
207 echo "-O";
208  $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
209  $nodeSet=array();
210  $i=0;
211  if (isset($myDOMNodeList))
212  while ($node=$myDOMNodeList->item($i))
213  {
214  $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
215  $i++;
216  }
217  return $nodeSet;
218  }
219 
220  function has_attribute($name)
221  {
222 echo "-P";
223  return $this->myDOMNode->hasAttribute($name);
224  }
225 
226  function remove_attribute($name)
227  {
228 echo "-Q";
229  return $this->myDOMNode->removeAttribute($name);
230  }
231 
232  function set_attribute($name,$value)
233  {
234 echo "-R";
235  return $this->myDOMNode->setAttribute($name,$value);
236  }
237 
238  function tagname()
239  {
240 echo "-S";
241  return $this->myDOMNode->tagName;
242  }
243 }
244 
245 class php4DOMNode
246 {
247  var $myDOMNode;
248  var $myOwnerDocument;
249 
250  function php4DOMNode($aDomNode,$aOwnerDocument)
251  {
252 echo "-T";
253  $this->myDOMNode=$aDomNode;
254  $this->myOwnerDocument=$aOwnerDocument;
255  }
256 
257  function __get($name)
258  {
259 echo "-U";
260  if ($name=='type') return $this->myDOMNode->nodeType;
261  elseif ($name=='tagname') return $this->myDOMNode->tagName;
262  elseif ($name=='content') return $this->myDOMNode->textContent;
263  else
264  {
265  $myErrors=debug_backtrace();
266  trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE);
267  return false;
268  }
269  }
270 
271  function append_child($newnode)
272  {
273 echo "-V";
274  return new php4DOMElement($this->myDOMNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);
275  }
276 
277  function append_sibling($newnode)
278  {
279 echo "-W";
280  return new php4DOMElement($this->myDOMNode->parentNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);
281  }
282 
283  function attributes()
284  {
285 echo "-X";
286  $myDOMNodeList=$this->myDOMNode->attributes;
287  $nodeSet=array();
288  $i=0;
289  if (isset($myDOMNodeList))
290  while ($node=$myDOMNodeList->item($i))
291  {
292  $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument);
293  $i++;
294  }
295  return $nodeSet;
296  }
297 
298  function child_nodes()
299  {
300 echo "-Y";
301  $myDOMNodeList=$this->myDOMNode->childNodes;
302  $nodeSet=array();
303  $i=0;
304  if (isset($myDOMNodeList))
305  while ($node=$myDOMNodeList->item($i))
306  {
307  $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument);
308  $i++;
309  }
310  return $nodeSet;
311  }
312 
313  function children() {
314 echo "-Z";
315  return $this->child_nodes();
316  }
317 
318  function clone_node($deep=false) {
319 echo "-a";
320  return new php4DOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);
321  }
322 
323  function first_child() {
324 echo "-b";
325  return new php4DOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);
326  }
327  function get_content() {
328 echo "-c";
329  return $this->myDOMNode->textContent;
330  }
331 
332  function has_attributes() {
333 echo "-d";
334  return $this->myDOMNode->hasAttributes();
335  }
336  function has_child_nodes()
337  {
338 echo "-e";
339  return $this->myDOMNode->hasChildNodes();
340  }
341  function insert_before($newnode,$refnode)
342  {
343 echo "-f";
344  return new php4DOMElement($this->myDOMNode->insertBefore($newnode->myDOMNode,$refnode->myDOMNode),$this->myOwnerDocument);
345  }
346 
347  function is_blank_node()
348  {
349 echo "-g";
350  $myDOMNodeList=$this->myDOMNode->childNodes;
351  $i=0;
352  if (isset($myDOMNodeList))
353  while ($node=$myDOMNodeList->item($i))
354  {
355  if (($node->nodeType==XML_ELEMENT_NODE)||
356  (($node->nodeType==XML_TEXT_NODE)&&!ereg('^([[:cntrl:]]|[[:space:]])*$',$node->nodeValue)))
357  return false;
358  $i++;
359  }
360  return true;
361  }
362 
363  function last_child() {
364 echo "-h";
365  return new php4DOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);
366  }
367 
368  function new_child($name,$content)
369  {
370 echo "-i";
371  $mySubNode=$this->myDOMNode->ownerDocument->createElement($name);
372  $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($content));
373  $this->myDOMNode->appendChild($mySubNode);
374  return new php4DOMElement($mySubNode,$this->myOwnerDocument);
375  }
376 
377  function next_sibling() {
378 echo "-j";
379  return new php4DOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);
380  }
381 
382  function node_name() {
383 echo "-k";
384  return $this->myDOMNode->localName;
385  }
386 
387  function node_type() {
388 echo "-l";
389  return $this->myDOMNode->nodeType;
390  }
391 
392  function node_value()
393  {
394 echo "-m";
395  return $this->myDOMNode->nodeValue;
396  }
397 
398  function owner_document()
399  {
400 echo "-n";
401  return $this->myOwnerDocument;
402  }
403 
404  function parent_node() {
405 echo "-o";
406  return new php4DOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);
407  }
408 
409  function prefix() {
410 echo "-p";
411  return $this->myDOMNode->prefix;
412  }
413 
414  function previous_sibling() {
415 echo "-q";
416  return new php4DOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);
417  }
418 
419  function remove_child($oldchild)
420  {
421 echo "-r";
422  return new php4DOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);
423  }
424 
425  function replace_child($oldnode,$newnode) {
426 echo "-s";
427  return new php4DOMElement($this->myDOMNode->replaceChild($oldnode->myDOMNode,$newnode->myDOMNode),$this->myOwnerDocument);
428  }
429 
430  function set_content($text)
431  {
432 echo "-t";
433  if (($this->myDOMNode->hasChildNodes())&&($this->myDOMNode->firstChild->nodeType==XML_TEXT_NODE))
434  $this->myDOMNode->removeChild($this->myDOMNode->firstChild);
435  return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($text));
436  }
437 }
438 
439 class php4DOMNodelist
440 {
441  var $myDOMNodelist;
442  var $nodeset;
443 
444  function php4DOMNodelist($aDOMNodelist,$aOwnerDocument)
445  {
446 echo "-u";
447  $this->myDOMNodelist=$aDOMNodelist;
448  $this->nodeset=array();
449  $i=0;
450  if (isset($this->myDOMNodelist))
451  while ($node=$this->myDOMNodelist->item($i))
452  {
453  $this->nodeset[]=new php4DOMElement($node,$aOwnerDocument);
454  $i++;
455  }
456  }
457 }
458 
459 class php4DOMXPath
460 {
461  var $myDOMXPath;
462  var $myOwnerDocument;
463  function php4DOMXPath($dom_document)
464  {
465 echo "-v";
466  $this->myOwnerDocument=$dom_document;
467  $this->myDOMXPath=new DOMXPath($dom_document->myDOMNode);
468  }
469 
470  function query($eval_str,$contextnode)
471  {
472 echo "-w";
473  if (isset($contextnode)) return new php4DOMNodelist($this->myDOMXPath->query($eval_str,$contextnode->myDOMNode),$this->myOwnerDocument);
474  else return new php4DOMNodelist($this->myDOMXPath->query($eval_str),$this->myOwnerDocument);
475  }
476 
477  function xpath_register_ns($prefix,$namespaceURI)
478  {
479 echo "-x";
480  return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);
481  }
482 }
483 
484 if (extension_loaded('xsl'))
485 {//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/
486 
487  function domxml_xslt_stylesheet($xslstring)
488  {
489 echo "-y";
490  return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));
491  }
492 
493  function domxml_xslt_stylesheet_doc($dom_document) {
494 echo "-z";
495  return new php4DomXsltStylesheet($dom_document);
496  }
497 
498  function domxml_xslt_stylesheet_file($xslfile) {
499 echo "-Ä";
500  return new php4DomXsltStylesheet(DOMDocument::load($xslfile));
501  }
502 
503  class php4DomXsltStylesheet
504  {
505  var $myxsltProcessor;
506  function php4DomXsltStylesheet($dom_document)
507  {
508 echo "-Ö";
509  $this->myxsltProcessor=new xsltProcessor();
510  $this->myxsltProcessor->importStyleSheet($dom_document);
511  }
512 
513  function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false)
514  {
515 echo "-Ü";
516  foreach ($xslt_parameters as $param=>$value)
517  $this->myxsltProcessor->setParameter('',$param,$value);
518  $myphp4DOMDocument=new php4DOMDocument();
519  $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode);
520  return $myphp4DOMDocument;
521  }
522 
523  function result_dump_file($dom_document,$filename)
524  {
525 echo "-ä";
526  $html=$dom_document->myDOMNode->saveHTML();
527  file_put_contents($filename,$html);
528  return $html;
529  }
530 
531  function result_dump_mem($dom_document) {
532 echo "-ö";
533  return $dom_document->myDOMNode->saveHTML();
534  }
535  }
536 }
537 
538 ?>