Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

CAS/domxml-php4-php5.php

Go to the documentation of this file.
00001 <?php 00037 function domxml_new_doc($version) {return new php4DOMDocument('');} 00038 function domxml_open_file($filename) {return new php4DOMDocument($filename);} 00039 function domxml_open_mem($str) 00040 { 00041 $dom=new php4DOMDocument(''); 00042 $dom->myDOMNode->loadXML($str); 00043 return $dom; 00044 } 00045 function xpath_eval($xpath_context,$eval_str,$contextnode=null) {return $xpath_context->query($eval_str,$contextnode);} 00046 function xpath_new_context($dom_document) {return new php4DOMXPath($dom_document);} 00047 00048 class php4DOMAttr extends php4DOMNode 00049 { 00050 function php4DOMAttr($aDOMAttr) {$this->myDOMNode=$aDOMAttr;} 00051 function Name() {return $this->myDOMNode->name;} 00052 function Specified() {return $this->myDOMNode->specified;} 00053 function Value() {return $this->myDOMNode->value;} 00054 } 00055 00056 class php4DOMDocument extends php4DOMNode 00057 { 00058 function php4DOMDocument($filename='') 00059 { 00060 $this->myDOMNode=new DOMDocument(); 00061 if ($filename!='') $this->myDOMNode->load($filename); 00062 } 00063 function create_attribute($name,$value) 00064 { 00065 $myAttr=$this->myDOMNode->createAttribute($name); 00066 $myAttr->value=$value; 00067 return new php4DOMAttr($myAttr,$this); 00068 } 00069 function create_cdata_section($content) {return new php4DOMNode($this->myDOMNode->createCDATASection($content),$this);} 00070 function create_comment($data) {return new php4DOMNode($this->myDOMNode->createComment($data),$this);} 00071 function create_element($name) {return new php4DOMElement($this->myDOMNode->createElement($name),$this);} 00072 function create_text_node($content) {return new php4DOMNode($this->myDOMNode->createTextNode($content),$this);} 00073 function document_element() {return new php4DOMElement($this->myDOMNode->documentElement,$this);} 00074 function dump_file($filename,$compressionmode=false,$format=false) {return $this->myDOMNode->save($filename);} 00075 function dump_mem($format=false,$encoding=false) {return $this->myDOMNode->saveXML();} 00076 function get_element_by_id($id) {return new php4DOMElement($this->myDOMNode->getElementById($id),$this);} 00077 function get_elements_by_tagname($name) 00078 { 00079 $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); 00080 $nodeSet=array(); 00081 $i=0; 00082 if (isset($myDOMNodeList)) 00083 while ($node=$myDOMNodeList->item($i)) 00084 { 00085 $nodeSet[]=new php4DOMElement($node,$this); 00086 $i++; 00087 } 00088 return $nodeSet; 00089 } 00090 function html_dump_mem() {return $this->myDOMNode->saveHTML();} 00091 function root() {return new php4DOMElement($this->myDOMNode->documentElement,$this);} 00092 } 00093 00094 class php4DOMElement extends php4DOMNode 00095 { 00096 function get_attribute($name) {return $this->myDOMNode->getAttribute($name);} 00097 function get_elements_by_tagname($name) 00098 { 00099 $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name); 00100 $nodeSet=array(); 00101 $i=0; 00102 if (isset($myDOMNodeList)) 00103 while ($node=$myDOMNodeList->item($i)) 00104 { 00105 $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument); 00106 $i++; 00107 } 00108 return $nodeSet; 00109 } 00110 function has_attribute($name) {return $this->myDOMNode->hasAttribute($name);} 00111 function remove_attribute($name) {return $this->myDOMNode->removeAttribute($name);} 00112 function set_attribute($name,$value) {return $this->myDOMNode->setAttribute($name,$value);} 00113 function tagname() {return $this->myDOMNode->tagName;} 00114 } 00115 00116 class php4DOMNode 00117 { 00118 var $myDOMNode; 00119 var $myOwnerDocument; 00120 function php4DOMNode($aDomNode,$aOwnerDocument) 00121 { 00122 $this->myDOMNode=$aDomNode; 00123 $this->myOwnerDocument=$aOwnerDocument; 00124 } 00125 function __get($name) 00126 { 00127 if ($name=='type') return $this->myDOMNode->nodeType; 00128 elseif ($name=='tagname') return $this->myDOMNode->tagName; 00129 elseif ($name=='content') return $this->myDOMNode->textContent; 00130 else 00131 { 00132 $myErrors=debug_backtrace(); 00133 trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE); 00134 return false; 00135 } 00136 } 00137 function append_child($newnode) {return new php4DOMElement($this->myDOMNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);} 00138 function append_sibling($newnode) {return new php4DOMElement($this->myDOMNode->parentNode->appendChild($newnode->myDOMNode),$this->myOwnerDocument);} 00139 function attributes() 00140 { 00141 $myDOMNodeList=$this->myDOMNode->attributes; 00142 $nodeSet=array(); 00143 $i=0; 00144 if (isset($myDOMNodeList)) 00145 while ($node=$myDOMNodeList->item($i)) 00146 { 00147 $nodeSet[]=new php4DOMAttr($node,$this->myOwnerDocument); 00148 $i++; 00149 } 00150 return $nodeSet; 00151 } 00152 function child_nodes() 00153 { 00154 $myDOMNodeList=$this->myDOMNode->childNodes; 00155 $nodeSet=array(); 00156 $i=0; 00157 if (isset($myDOMNodeList)) 00158 while ($node=$myDOMNodeList->item($i)) 00159 { 00160 $nodeSet[]=new php4DOMElement($node,$this->myOwnerDocument); 00161 $i++; 00162 } 00163 return $nodeSet; 00164 } 00165 function children() {return $this->child_nodes();} 00166 function clone_node($deep=false) {return new php4DOMElement($this->myDOMNode->cloneNode($deep),$this->myOwnerDocument);} 00167 function first_child() {return new php4DOMElement($this->myDOMNode->firstChild,$this->myOwnerDocument);} 00168 function get_content() {return $this->myDOMNode->textContent;} 00169 function has_attributes() {return $this->myDOMNode->hasAttributes();} 00170 function has_child_nodes() {return $this->myDOMNode->hasChildNodes();} 00171 function insert_before($newnode,$refnode) {return new php4DOMElement($this->myDOMNode->insertBefore($newnode->myDOMNode,$refnode->myDOMNode),$this->myOwnerDocument);} 00172 function is_blank_node() 00173 { 00174 $myDOMNodeList=$this->myDOMNode->childNodes; 00175 $i=0; 00176 if (isset($myDOMNodeList)) 00177 while ($node=$myDOMNodeList->item($i)) 00178 { 00179 if (($node->nodeType==XML_ELEMENT_NODE)|| 00180 (($node->nodeType==XML_TEXT_NODE)&&!preg_match('/^([[:cntrl:]]|[[:space:]])*$/',$node->nodeValue))) 00181 return false; 00182 $i++; 00183 } 00184 return true; 00185 } 00186 function last_child() {return new php4DOMElement($this->myDOMNode->lastChild,$this->myOwnerDocument);} 00187 function new_child($name,$content) 00188 { 00189 $mySubNode=$this->myDOMNode->ownerDocument->createElement($name); 00190 $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($content)); 00191 $this->myDOMNode->appendChild($mySubNode); 00192 return new php4DOMElement($mySubNode,$this->myOwnerDocument); 00193 } 00194 function next_sibling() {return new php4DOMElement($this->myDOMNode->nextSibling,$this->myOwnerDocument);} 00195 function node_name() {return $this->myDOMNode->localName;} 00196 function node_type() {return $this->myDOMNode->nodeType;} 00197 function node_value() {return $this->myDOMNode->nodeValue;} 00198 function owner_document() {return $this->myOwnerDocument;} 00199 function parent_node() {return new php4DOMElement($this->myDOMNode->parentNode,$this->myOwnerDocument);} 00200 function prefix() {return $this->myDOMNode->prefix;} 00201 function previous_sibling() {return new php4DOMElement($this->myDOMNode->previousSibling,$this->myOwnerDocument);} 00202 function remove_child($oldchild) {return new php4DOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode),$this->myOwnerDocument);} 00203 function replace_child($oldnode,$newnode) {return new php4DOMElement($this->myDOMNode->replaceChild($oldnode->myDOMNode,$newnode->myDOMNode),$this->myOwnerDocument);} 00204 function set_content($text) 00205 { 00206 if (($this->myDOMNode->hasChildNodes())&&($this->myDOMNode->firstChild->nodeType==XML_TEXT_NODE)) 00207 $this->myDOMNode->removeChild($this->myDOMNode->firstChild); 00208 return $this->myDOMNode->appendChild($this->myDOMNode->ownerDocument->createTextNode($text)); 00209 } 00210 } 00211 00212 class php4DOMNodelist 00213 { 00214 var $myDOMNodelist; 00215 var $nodeset; 00216 function php4DOMNodelist($aDOMNodelist,$aOwnerDocument) 00217 { 00218 $this->myDOMNodelist=$aDOMNodelist; 00219 $this->nodeset=array(); 00220 $i=0; 00221 if (isset($this->myDOMNodelist)) 00222 while ($node=$this->myDOMNodelist->item($i)) 00223 { 00224 $this->nodeset[]=new php4DOMElement($node,$aOwnerDocument); 00225 $i++; 00226 } 00227 } 00228 } 00229 00230 class php4DOMXPath 00231 { 00232 var $myDOMXPath; 00233 var $myOwnerDocument; 00234 function php4DOMXPath($dom_document) 00235 { 00236 $this->myOwnerDocument=$dom_document; 00237 $this->myDOMXPath=new DOMXPath($dom_document->myDOMNode); 00238 } 00239 function query($eval_str,$contextnode) 00240 { 00241 if (isset($contextnode)) return new php4DOMNodelist($this->myDOMXPath->query($eval_str,$contextnode->myDOMNode),$this->myOwnerDocument); 00242 else return new php4DOMNodelist($this->myDOMXPath->query($eval_str),$this->myOwnerDocument); 00243 } 00244 function xpath_register_ns($prefix,$namespaceURI) {return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);} 00245 } 00246 00247 if (extension_loaded('xsl')) 00248 {//See also: http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/ 00249 function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));} 00250 function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);} 00251 function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));} 00252 class php4DomXsltStylesheet 00253 { 00254 var $myxsltProcessor; 00255 function php4DomXsltStylesheet($dom_document) 00256 { 00257 $this->myxsltProcessor=new xsltProcessor(); 00258 $this->myxsltProcessor->importStyleSheet($dom_document); 00259 } 00260 function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false) 00261 { 00262 foreach ($xslt_parameters as $param=>$value) 00263 $this->myxsltProcessor->setParameter('',$param,$value); 00264 $myphp4DOMDocument=new php4DOMDocument(); 00265 $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode); 00266 return $myphp4DOMDocument; 00267 } 00268 function result_dump_file($dom_document,$filename) 00269 { 00270 $html=$dom_document->myDOMNode->saveHTML(); 00271 file_put_contents($filename,$html); 00272 return $html; 00273 } 00274 function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();} 00275 } 00276 } 00277 ?>

Generated on Thu Aug 17 02:03:21 2006 for phpCAS by doxygen 1.3.7