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 $text_node =& new DOMText();
00247 $text_node->appendData($text);
00248 if (is_object($this->myDOMNode->firstChild))
00249 {
00250 $this->myDOMNode->replaceChild($text_node, $this->myDOMNode->firstChild);
00251 }
00252 else
00253 {
00254 $this->myDOMNode->appendChild($text_node);
00255 }
00256 }
00257
00258
00259 function get_content()
00260 {
00261 $text_node =& $this->myDOMNode->firstChild;
00262
00263 if (is_object($text_node))
00264 {
00265 return $text_node->textContent;
00266 }
00267 else
00268 {
00269 return "";
00270 }
00271 }
00272
00273
00274 function unlink($aDomNode)
00275 {
00276 parent::unlink_node($aDomNode);
00277 }
00278
00279 }
00280
00284 class php4DOMNode
00285 {
00286 var $myDOMNode;
00287
00288 function php4DOMNode($aDomNode)
00289 {
00290 $this->myDOMNode=$aDomNode;
00291 }
00292
00293 function append_child($newnode)
00294 {
00295
00296
00297
00298 $doc =& $this->myDOMNode->ownerDocument;
00299
00300 $newnode->myDOMNode =& $doc->importNode($newnode->myDOMNode, true);
00301
00302 return new php4DOMElement($this->myDOMNode->appendChild($newnode->myDOMNode));
00303
00304
00305
00306
00307 }
00308
00309 function replace_node($newnode)
00310 {
00311 return $this->set_content($newnode->myDOMNode->textContent);
00312 }
00313
00314 function append_sibling($newnode)
00315 {
00316 return new php4DOMElement($this->myDOMNode->parentNode->appendChild($newnode->myDOMNode));
00317 }
00318
00319 function attributes()
00320 {
00321
00322 $myDOMNodeList=$this->myDOMNode->attributes;
00323 $nodeSet=array();
00324 $i=0;
00325 if (is_object($myDOMNodeList))
00326 {
00327 while ($node=$myDOMNodeList->item($i))
00328 {
00329 $nodeSet[]=new php4DOMAttr($node);
00330 $i++;
00331 }
00332 }
00333
00334 return $nodeSet;
00335 }
00336
00337 function child_nodes()
00338 {
00339 $myDOMNodeList=$this->myDOMNode->childNodes;
00340 $nodeSet=array();
00341 $i=0;
00342 while ($node=$myDOMNodeList->item($i))
00343 {
00344 $nodeSet[]=new php4DOMElement($node);
00345 $i++;
00346 }
00347 return $nodeSet;
00348 }
00349
00350
00351 function children()
00352 {
00353
00354 return $this->child_nodes();
00355 }
00356
00357
00358 function unlink_node($aDomNode = "")
00359 {
00360
00361 if (!is_object($aDomNode))
00362 {
00363 $aDomNode =& $this;
00364 }
00365
00366 $parent =& $aDomNode->myDOMNode->parentNode;
00367 if (is_object($parent))
00368 {
00369 $parent->removeChild($aDomNode->myDOMNode);
00370 }
00371 }
00372
00373 function clone_node($deep=false)
00374 {
00375 return new php4DOMElement($this->myDOMNode->cloneNode($deep));
00376 }
00377
00378 function first_child()
00379 {
00380 return new php4DOMElement($this->myDOMNode->firstChild);
00381 }
00382
00383 function get_content()
00384 {
00385 return $this->myDOMNode->textContent;
00386 }
00387
00388 function has_attributes()
00389 {
00390 return $this->myDOMNode->hasAttributes();
00391 }
00392
00393 function has_child_nodes()
00394 {
00395 return $this->myDOMNode->hasChildNodes();
00396 }
00397
00398
00399 function insert_before($newnode,$refnode)
00400 {
00401
00402 $doc =& $this->myDOMNode->ownerDocument;
00403 $newnode->myDOMNode =& $doc->importNode($newnode->myDOMNode, true);
00404
00405 $mydomnode =& $this->myDOMNode;
00406 $mynewnode =& $newnode->myDOMNode;
00407 $myrefnode =& $refnode->myDOMNode;
00408 try
00409 {
00410 $domel =& $mydomnode->insertBefore($mynewnode,$myrefnode);
00411 }
00412 catch (DOMException $exception)
00413 {
00414
00415 $mydomnode =& $this->myDOMNode->parentNode;
00416 $domel =& $mydomnode->insertBefore($mynewnode,$myrefnode);
00417 }
00418 $el =& new php4DOMElement($domel);
00419 return $el;
00420 }
00421
00422
00423 function last_child()
00424 {
00425 $last =& $this->myDOMNode->lastChild;
00426
00427 if (is_object($last))
00428 {
00429 return new php4DOMElement($last);
00430 }
00431 else
00432 {
00433 return false;
00434 }
00435 }
00436
00437
00438 function next_sibling()
00439 {
00440 $next =& $this->myDOMNode->nextSibling;
00441
00442 if (is_object($next))
00443 {
00444 return new php4DOMElement($next);
00445 }
00446 else
00447 {
00448 return false;
00449 }
00450 }
00451
00452 function node_name()
00453 {
00454 return $this->myDOMNode->nodeName;
00455 }
00456
00457 function node_type()
00458 {
00459 return $this->myDOMNode->nodeType;
00460 }
00461
00462 function node_value()
00463 {
00464 return $this->myDOMNode->nodeValue;
00465 }
00466
00467
00468 function parent_node()
00469 {
00470 $parent =& $this->myDOMNode->parentNode;
00471
00472 if (is_object($parent))
00473 {
00474 return new php4DOMElement($parent);
00475 }
00476 else
00477 {
00478 return false;
00479 }
00480 }
00481
00482
00483 function previous_sibling()
00484 {
00485 $prev =& $this->myDOMNode->previousSibling;
00486
00487 if (is_object($prev))
00488 {
00489 return new php4DOMElement($prev);
00490 }
00491 else
00492 {
00493 return false;
00494 }
00495 }
00496
00497 function remove_child($oldchild)
00498 {
00499 return new php4DOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode));
00500 }
00501
00502 function replace_child($oldnode,$newnode)
00503 {
00504 return new php4DOMElement($this->myDOMNode->replaceChild($oldchild->myDOMNode,$newnode->myDOMNode));
00505 }
00506
00507 function set_content($text)
00508 {
00509 $this->myDOMNode->textContent = $text;
00510 return $this->myDOMNode->textContent;
00511 }
00512 }
00513
00514 class php4DOMNodelist
00515 {
00516 var $myDOMNodelist;
00517 var $nodeset;
00518
00519 function php4DOMNodelist($aDOMNodelist)
00520 {
00521 $this->myDOMNodelist=$aDOMNodelist;
00522 $this->nodeset=array();
00523 $i=0;
00524 while ($node=$this->myDOMNodelist->item($i))
00525 {
00526 $this->nodeset[]=new php4DOMElement($node);
00527 $i++;
00528 }
00529 }
00530 }
00531
00532 class php4DOMXPath
00533 {
00534 var $myDOMXPath;
00535
00536
00537 function xpath_eval($eval_str)
00538 {
00539 return xpath_eval($this, $eval_str);
00540 }
00541
00542 function php4DOMXPath($dom_document)
00543 {
00544 $this->myDOMXPath=new DOMXPath($dom_document->myDOMDocument);
00545 }
00546
00547 function query($eval_str)
00548 {
00549 return new php4DOMNodelist($this->myDOMXPath->query($eval_str));
00550 }
00551
00552 function xpath_register_ns($prefix,$namespaceURI)
00553 {
00554 return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);
00555 }
00556 }
00557
00558 ?>