Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 function domxml_open_file($filename)
00025 {
00026 return new php4DOMDocument($filename);
00027 }
00028
00029
00030
00031
00032 function domxml_open_mem($str)
00033 {
00034 return new php4DOMDocument($str, false);
00035 }
00036
00037 function xpath_eval($xpath_context,$eval_str)
00038 {
00039 return $xpath_context->query($eval_str);
00040 }
00041
00042 function xpath_new_context($dom_document)
00043 {
00044 return new php4DOMXPath($dom_document);
00045 }
00046
00047 class php4DOMAttr extends php4DOMNode
00048 {
00049 var $myDOMAttr;
00050
00051 function php4DOMAttr($aDOMAttr)
00052 {
00053 $this->myDOMAttr=$aDOMAttr;
00054 }
00055
00056 function Name()
00057 {
00058 return $this->myDOMAttr->name;
00059 }
00060
00061 function Specified()
00062 {
00063 return $this->myDOMAttr->specified;
00064 }
00065
00066 function Value()
00067 {
00068 return $this->myDOMAttr->value;
00069 }
00070 }
00071
00072 class php4DOMCDATASection extends php4DOMNode
00073 {
00074 var $myDOMCDATASection;
00075
00076 function php4DOMCDATASection($aDOMCDATASection)
00077 {
00078 parent::php4DOMNode($aDOMCDATASection);
00079 $this->myDOMCDATASection=$aDOMCDATASection;
00080 }
00081 }
00082
00083 class php4DOMDocument
00084 {
00085 var $myDOMDocument;
00086
00087
00088 function php4DOMDocument($source, $file = true)
00089 {
00090 $this->myDOMDocument=new DOMDocument();
00091 if ($file)
00092 {
00093 $this->myDOMDocument->load($source);
00094 }
00095 else
00096 {
00097 $this->myDOMDocument->loadXML($source);
00098 }
00099 }
00100
00101
00102 function xpath_init()
00103 {
00104 }
00105
00106 function free()
00107 {
00108 unset($this->myDOMDocument);
00109 }
00110
00111
00112 function xpath_new_context()
00113 {
00114 return xpath_new_context($this);
00115 }
00116
00117
00118 function dump_node($node)
00119 {
00120 $str = $this->myDOMDocument->saveXML($node->myDOMNode);
00121 return $str;
00122 }
00123
00124
00125 function validate(&$error)
00126 {
00127 $ok = $this->myDOMDocument->validate();
00128 if (!$ok)
00129 {
00130 $error = array(array("0", "Unknown Error"));
00131 }
00132 return $error;
00133 }
00134
00135 function create_attribute($name,$value)
00136 {
00137 $myAttr=$this->myDOMDocument->createAttribute($name);
00138 $myAttr->value=$value;
00139
00140 return new php4DOMAttr($myAttr);
00141 }
00142
00143 function create_cdata_section($content)
00144 {
00145 return new php4DOMCDATASection($this->myDOMDocument->createCDATASection($content));
00146 }
00147
00148 function create_comment($data)
00149 {
00150 return new php4DOMElement($this->myDOMDocument->createComment($data));
00151 }
00152
00153 function create_element($name)
00154 {
00155 return new php4DOMElement($this->myDOMDocument->createElement($name));
00156 }
00157
00158 function create_text_node($content)
00159 {
00160 return new php4DOMNode($this->myDOMDocument->createTextNode($content));
00161 }
00162
00163 function document_element()
00164 {
00165 return new php4DOMElement($this->myDOMDocument->documentElement);
00166 }
00167
00168 function dump_file($filename,$compressionmode=false,$format=false)
00169 {
00170 return $this->myDOMDocument->save($filename);
00171 }
00172
00173 function dump_mem($format=false,$encoding=false)
00174 {
00175 return $this->myDOMDocument->saveXML();
00176 }
00177
00178 function get_elements_by_tagname($name)
00179 {
00180 $myDOMNodeList=$this->myDOMDocument->getElementsByTagName($name);
00181 $nodeSet=array();
00182 $i=0;
00183 while ($node=$myDOMNodeList->item($i))
00184 {
00185 $nodeSet[]=new php4DOMElement($node);
00186 $i++;
00187 }
00188
00189 return $nodeSet;
00190 }
00191
00192 function html_dump_mem()
00193 {
00194 return $this->myDOMDocument->saveHTML();
00195 }
00196
00197 }
00198
00202 class php4DOMElement extends php4DOMNode
00203 {
00204 function get_attribute($name)
00205 {
00206 return $this->myDOMNode->getAttribute($name);
00207 }
00208
00209 function get_elements_by_tagname($name)
00210 {
00211 $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
00212 $nodeSet=array();
00213 $i=0;
00214 while ($node=$myDOMNodeList->item($i))
00215 {
00216 $nodeSet[]=new php4DOMElement($node);
00217 $i++;
00218 }
00219
00220 return $nodeSet;
00221 }
00222
00223 function has_attribute($name)
00224 {
00225 return $this->myDOMNode->hasAttribute($name);
00226 }
00227
00228 function remove_attribute($name)
00229 {
00230 return $this->myDOMNode->removeAttribute($name);
00231 }
00232
00233 function set_attribute($name,$value)
00234 {
00235 return $this->myDOMNode->setAttribute($name,$value);
00236 }
00237
00238 function tagname()
00239 {
00240 return $this->myDOMNode->tagName;
00241 }
00242
00243
00244 function set_content($text)
00245 {
00246
00247
00248
00249 $text = str_replace("<", "<", $text);
00250 $text = str_replace(">", ">", $text);
00251 $text = str_replace("&", "&", $text);
00252
00253 $text_node =& new DOMText();
00254 $text_node->appendData($text);
00255 if (is_object($this->myDOMNode->firstChild))
00256 {
00257 $this->myDOMNode->replaceChild($text_node, $this->myDOMNode->firstChild);
00258 }
00259 else
00260 {
00261 $this->myDOMNode->appendChild($text_node);
00262 }
00263 }
00264
00265
00266 function get_content()
00267 {
00268 $text_node =& $this->myDOMNode->firstChild;
00269
00270 if (is_object($text_node))
00271 {
00272 return $text_node->textContent;
00273 }
00274 else
00275 {
00276 return "";
00277 }
00278 }
00279
00280
00281 function unlink($aDomNode)
00282 {
00283 parent::unlink_node($aDomNode);
00284 }
00285
00286 }
00287
00291 class php4DOMNode
00292 {
00293 var $myDOMNode;
00294
00295 function php4DOMNode($aDomNode)
00296 {
00297 $this->myDOMNode=$aDomNode;
00298 }
00299
00300 function append_child($newnode)
00301 {
00302
00303
00304
00305 $doc =& $this->myDOMNode->ownerDocument;
00306
00307 $newnode->myDOMNode =& $doc->importNode($newnode->myDOMNode, true);
00308
00309 return new php4DOMElement($this->myDOMNode->appendChild($newnode->myDOMNode));
00310
00311
00312
00313
00314 }
00315
00316 function replace_node($newnode)
00317 {
00318 return $this->set_content($newnode->myDOMNode->textContent);
00319 }
00320
00321 function append_sibling($newnode)
00322 {
00323 return new php4DOMElement($this->myDOMNode->parentNode->appendChild($newnode->myDOMNode));
00324 }
00325
00326 function attributes()
00327 {
00328
00329 $myDOMNodeList=$this->myDOMNode->attributes;
00330 $nodeSet=array();
00331 $i=0;
00332 if (is_object($myDOMNodeList))
00333 {
00334 while ($node=$myDOMNodeList->item($i))
00335 {
00336 $nodeSet[]=new php4DOMAttr($node);
00337 $i++;
00338 }
00339 }
00340
00341 return $nodeSet;
00342 }
00343
00344 function child_nodes()
00345 {
00346 $myDOMNodeList=$this->myDOMNode->childNodes;
00347 $nodeSet=array();
00348 $i=0;
00349 while ($node=$myDOMNodeList->item($i))
00350 {
00351 $nodeSet[]=new php4DOMElement($node);
00352 $i++;
00353 }
00354 return $nodeSet;
00355 }
00356
00357
00358 function children()
00359 {
00360
00361 return $this->child_nodes();
00362 }
00363
00364
00365 function unlink_node($aDomNode = "")
00366 {
00367
00368 if (!is_object($aDomNode))
00369 {
00370 $aDomNode =& $this;
00371 }
00372
00373 $parent =& $aDomNode->myDOMNode->parentNode;
00374 if (is_object($parent))
00375 {
00376 $parent->removeChild($aDomNode->myDOMNode);
00377 }
00378 }
00379
00380 function clone_node($deep=false)
00381 {
00382 return new php4DOMElement($this->myDOMNode->cloneNode($deep));
00383 }
00384
00385 function first_child()
00386 {
00387 return new php4DOMElement($this->myDOMNode->firstChild);
00388 }
00389
00390 function get_content()
00391 {
00392 return $this->myDOMNode->textContent;
00393 }
00394
00395 function has_attributes()
00396 {
00397 return $this->myDOMNode->hasAttributes();
00398 }
00399
00400 function has_child_nodes()
00401 {
00402 return $this->myDOMNode->hasChildNodes();
00403 }
00404
00405
00406 function insert_before($newnode,$refnode)
00407 {
00408
00409 $doc =& $this->myDOMNode->ownerDocument;
00410 $newnode->myDOMNode =& $doc->importNode($newnode->myDOMNode, true);
00411
00412 $mydomnode =& $this->myDOMNode;
00413 $mynewnode =& $newnode->myDOMNode;
00414 $myrefnode =& $refnode->myDOMNode;
00415 try
00416 {
00417 $domel =& $mydomnode->insertBefore($mynewnode,$myrefnode);
00418 }
00419 catch (DOMException $exception)
00420 {
00421
00422 $mydomnode =& $this->myDOMNode->parentNode;
00423 $domel =& $mydomnode->insertBefore($mynewnode,$myrefnode);
00424 }
00425 $el =& new php4DOMElement($domel);
00426 return $el;
00427 }
00428
00429
00430 function last_child()
00431 {
00432 $last =& $this->myDOMNode->lastChild;
00433
00434 if (is_object($last))
00435 {
00436 return new php4DOMElement($last);
00437 }
00438 else
00439 {
00440 return false;
00441 }
00442 }
00443
00444
00445 function next_sibling()
00446 {
00447 $next =& $this->myDOMNode->nextSibling;
00448
00449 if (is_object($next))
00450 {
00451 return new php4DOMElement($next);
00452 }
00453 else
00454 {
00455 return false;
00456 }
00457 }
00458
00459 function node_name()
00460 {
00461 return $this->myDOMNode->nodeName;
00462 }
00463
00464 function node_type()
00465 {
00466 return $this->myDOMNode->nodeType;
00467 }
00468
00469 function node_value()
00470 {
00471 return $this->myDOMNode->nodeValue;
00472 }
00473
00474
00475 function parent_node()
00476 {
00477 $parent =& $this->myDOMNode->parentNode;
00478
00479 if (is_object($parent))
00480 {
00481 return new php4DOMElement($parent);
00482 }
00483 else
00484 {
00485 return false;
00486 }
00487 }
00488
00489
00490 function previous_sibling()
00491 {
00492 $prev =& $this->myDOMNode->previousSibling;
00493
00494 if (is_object($prev))
00495 {
00496 return new php4DOMElement($prev);
00497 }
00498 else
00499 {
00500 return false;
00501 }
00502 }
00503
00504 function remove_child($oldchild)
00505 {
00506 return new php4DOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode));
00507 }
00508
00509 function replace_child($oldnode,$newnode)
00510 {
00511 return new php4DOMElement($this->myDOMNode->replaceChild($oldchild->myDOMNode,$newnode->myDOMNode));
00512 }
00513
00514 function set_content($text)
00515 {
00516 $this->myDOMNode->textContent = $text;
00517 return $this->myDOMNode->textContent;
00518 }
00519 }
00520
00521 class php4DOMNodelist
00522 {
00523 var $myDOMNodelist;
00524 var $nodeset;
00525
00526 function php4DOMNodelist($aDOMNodelist)
00527 {
00528 $this->myDOMNodelist=$aDOMNodelist;
00529 $this->nodeset=array();
00530 $i=0;
00531 while ($node=$this->myDOMNodelist->item($i))
00532 {
00533 $this->nodeset[]=new php4DOMElement($node);
00534 $i++;
00535 }
00536 }
00537 }
00538
00539 class php4DOMXPath
00540 {
00541 var $myDOMXPath;
00542
00543
00544 function xpath_eval($eval_str)
00545 {
00546 return xpath_eval($this, $eval_str);
00547 }
00548
00549 function php4DOMXPath($dom_document)
00550 {
00551 $this->myDOMXPath=new DOMXPath($dom_document->myDOMDocument);
00552 }
00553
00554 function query($eval_str)
00555 {
00556 return new php4DOMNodelist($this->myDOMXPath->query($eval_str));
00557 }
00558
00559 function xpath_register_ns($prefix,$namespaceURI)
00560 {
00561 return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);
00562 }
00563 }
00564
00565 ?>