94 {return array('errormessage'=>$error->message,'nodename'=>'','line'=>$error->line,'col'=>$error->column)+($error->file==''?array():array('directory'=>dirname($error->file),'file'=>basename($error->file)));}
96{
98 {
99 if ($name==='name') return $this->myDOMNode->name;
100 else return parent::__get($name);
101 }
102 function name() {
return $this->myDOMNode->name;}
104
105 function specified() {
return $this->myDOMNode->specified;}
106 function value() {
return $this->myDOMNode->value;}
107}
109{
111 {
112 $this->myDOMNode=new DOMDocument();
113 $this->myOwnerDocument=$this;
118 }
120 {
121 if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild);
122 return new php4DOMElement($this->myDOMNode->appendChild($this->myDOMNode->createElement($name)),$this->myOwnerDocument);
123 }
125 {
126 $myAttr=$this->myDOMNode->createAttribute($name);
127 $myAttr->value=htmlspecialchars($value,ENT_QUOTES);
129 }
134 {
135 if ($prefix==null) $prefix=$this->myDOMNode->lookupPrefix($uri);
136 if (($prefix==null)&&(($this->myDOMNode->documentElement==null)||(!$this->myDOMNode->documentElement->isDefaultNamespace($uri)))) $prefix='a'.sprintf('%u',crc32($uri));
137 return new php4DOMElement($this->myDOMNode->createElementNS($uri,$prefix==
null ? $name : $prefix.
':'.$name),$this);
138 }
142 function document_element() {
return parent::_newDOMElement($this->myDOMNode->documentElement,$this);}
144 {
145 $format0=$this->myDOMNode->formatOutput;
146 $this->myDOMNode->formatOutput=$format;
148 $this->myDOMNode->formatOutput=$format0;
150 }
151 function dump_mem($format=
false,$encoding=
false)
152 {
153 $format0=$this->myDOMNode->formatOutput;
154 $this->myDOMNode->formatOutput=$format;
155 $encoding0=$this->myDOMNode->encoding;
156 if ($encoding) $this->myDOMNode->encoding=$encoding;
157 $dump=$this->myDOMNode->saveXML();
158 $this->myDOMNode->formatOutput=$format0;
159 if ($encoding) $this->myDOMNode->encoding= $encoding0=='' ? 'UTF-8' : $encoding0;
160 return $dump;
161 }
163 {
164 if ($this->myDOMNode->hasChildNodes()) $this->myDOMNode->removeChild($this->myDOMNode->firstChild);
165 $this->myDOMNode=null;
166 $this->myOwnerDocument=null;
167 }
168 function get_element_by_id($id) {
return parent::_newDOMElement($this->myDOMNode->getElementById($id),$this);}
170 {
171 $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
172 $nodeSet=array();
173 $i=0;
174 if (isset($myDOMNodeList))
175 while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=
new php4DOMElement($node,$this);
176 return $nodeSet;
177 }
178 function html_dump_mem() {
return $this->myDOMNode->saveHTML();}
179 function root() {
return parent::_newDOMElement($this->myDOMNode->documentElement,$this);}
180 function xinclude() {
return $this->myDOMNode->xinclude();}
182}
184{
186 {
187 if ($this->myDOMNode->hasAttributeNS('http://www.w3.org/2000/xmlns/',$prefix)) return false;
188 else
189 {
190 $this->myDOMNode->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$prefix,$uri);
191 return true;
192 }
193 }
194 function get_attribute($name) {
return $this->myDOMNode->getAttribute($name);}
195 function get_attribute_node($name) {
return parent::_newDOMElement($this->myDOMNode->getAttributeNode($name),$this->myOwnerDocument);}
197 {
198 $myDOMNodeList=$this->myDOMNode->getElementsByTagName($name);
199 $nodeSet=array();
200 $i=0;
201 if (isset($myDOMNodeList))
202 while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=
new php4DOMElement($node,$this->myOwnerDocument);
203 return $nodeSet;
204 }
205 function has_attribute($name) {
return $this->myDOMNode->hasAttribute($name);}
206 function remove_attribute($name) {
return $this->myDOMNode->removeAttribute($name);}
208 {
209
210 $myAttr=$this->myDOMNode->ownerDocument->createAttribute($name);
211 $myAttr->value=htmlspecialchars($value,ENT_QUOTES);
212 $this->myDOMNode->setAttributeNode($myAttr);
213 return new php4DOMAttr($myAttr,$this->myOwnerDocument);
214 }
215
216
217
218
219
220
222 {
223 if ($this->myDOMNode->prefix=='') $newNode=$this->myDOMNode->ownerDocument->createElement($name);
224 else $newNode=$this->myDOMNode->ownerDocument->createElementNS($this->myDOMNode->namespaceURI,$this->myDOMNode->prefix.':'.$name);
225 $myDOMNodeList=$this->myDOMNode->attributes;
226 $i=0;
227 if (isset($myDOMNodeList))
228 while ($node=$myDOMNodeList->item($i++))
229 if ($node->namespaceURI=='') $newNode->setAttribute($node->name,$node->value);
230 else $newNode->setAttributeNS($node->namespaceURI,$node->nodeName,$node->value);
231 $myDOMNodeList=$this->myDOMNode->childNodes;
232 if (isset($myDOMNodeList))
233 while ($node=$myDOMNodeList->item(0)) $newNode->appendChild($node);
234 $this->myDOMNode->parentNode->replaceChild($newNode,$this->myDOMNode);
235 $this->myDOMNode=$newNode;
236 return true;
237 }
238 function tagname() {
return $this->tagname;}
239}
241{
245 {
246 $this->myDOMNode=$aDomNode;
247 $this->myOwnerDocument=$aOwnerDocument;
248 }
249 function __get($name)
250 {
251 switch ($name)
252 {
253 case 'type': return $this->myDOMNode->nodeType;
254 case 'tagname': return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->tagName;
255 case 'content': return $this->myDOMNode->textContent;
256 case 'value': return $this->myDOMNode->value;
257 default:
258 $myErrors=debug_backtrace();
259 trigger_error('Undefined property: '.get_class($this).'::$'.$name.' ['.$myErrors[0]['file'].':'.$myErrors[0]['line'].']',E_USER_NOTICE);
260 return false;
261 }
262 }
268 {
269 $myDOMNodeList=$this->myDOMNode->attributes;
270 if (!(isset($myDOMNodeList)&&$this->myDOMNode->hasAttributes())) return null;
271 $nodeSet=array();
272 $i=0;
273 while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=
new php4DOMAttr($node,$this->myOwnerDocument);
274 return $nodeSet;
275 }
277 {
278 $myDOMNodeList=$this->myDOMNode->childNodes;
279 $nodeSet=array();
280 $i=0;
281 if (isset($myDOMNodeList))
282 while ($node=$myDOMNodeList->item($i++)) $nodeSet[]=
self::_newDOMElement($node,$this->myOwnerDocument);
283 return $nodeSet;
284 }
287
288 function dump_node($node=
null) {
return $node==
null ? $this->myOwnerDocument->myDOMNode->saveXML($this->myDOMNode) : $this->myOwnerDocument->myDOMNode->saveXML($node->myDOMNode);}
290 function get_content() {
return $this->myDOMNode->textContent;}
291 function has_attributes() {
return $this->myDOMNode->hasAttributes();}
293 function insert_before($newnode,$refnode) {
return self::_newDOMElement($this->myDOMNode->insertBefore($this->_importNode($newnode),$refnode==
null?
null:$refnode->myDOMNode),$this->myOwnerDocument);}
294 function is_blank_node() {
return ($this->myDOMNode->nodeType===XML_TEXT_NODE)&&preg_match(
'%^\s*$%',$this->myDOMNode->nodeValue);}
297 {
298 $mySubNode=$this->myDOMNode->ownerDocument->createElement($name);
299 $mySubNode->appendChild($this->myDOMNode->ownerDocument->createTextNode(
_entityDecode($content)));
300 $this->myDOMNode->appendChild($mySubNode);
302 }
304 function node_name() {
return ($this->myDOMNode->nodeType===XML_ELEMENT_NODE) ? $this->myDOMNode->localName : $this->myDOMNode->nodeName;}
305 function node_type() {
return $this->myDOMNode->nodeType;}
306 function node_value() {
return $this->myDOMNode->nodeValue;}
309 function prefix() {
return $this->myDOMNode->prefix;}
312 function replace_child($newnode,$oldnode) {
return self::_newDOMElement($this->myDOMNode->replaceChild($this->_importNode($newnode),$oldnode->myDOMNode),$this->myOwnerDocument);}
313 function replace_node($newnode) {
return self::_newDOMElement($this->myDOMNode->parentNode->replaceChild($this->_importNode($newnode),$this->myDOMNode),$this->myOwnerDocument);}
315
317 {
318 $nsprefix=$this->myDOMNode->lookupPrefix($uri);
319 if ($nsprefix==null)
320 {
321 $nsprefix= $prefix==null ? $nsprefix='a'.sprintf('%u',crc32($uri)) : $prefix;
322 if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE)
323 {
324 if (($prefix!=null)&&$this->myDOMNode->ownerElement->hasAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)&&
325 ($this->myDOMNode->ownerElement->getAttributeNS('http://www.w3.org/2000/xmlns/',$nsprefix)!=$uri))
326 {
327 $parent=$this->myDOMNode->ownerElement;
328 $parent->removeAttributeNode($this->myDOMNode);
329 $parent->setAttribute($this->myDOMNode->localName,$this->myDOMNode->nodeValue);
330 $this->myDOMNode=$parent->getAttributeNode($this->myDOMNode->localName);
331 return;
332 }
333 $this->myDOMNode->ownerElement->setAttributeNS('http://www.w3.org/2000/xmlns/','xmlns:'.$nsprefix,$uri);
334 }
335 }
336 if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE)
337 {
338 $parent=$this->myDOMNode->ownerElement;
339 $parent->removeAttributeNode($this->myDOMNode);
340 $parent->setAttributeNS($uri,$nsprefix.':'.$this->myDOMNode->localName,$this->myDOMNode->nodeValue);
341 $this->myDOMNode=$parent->getAttributeNodeNS($uri,$this->myDOMNode->localName);
342 }
343 elseif ($this->myDOMNode->nodeType===XML_ELEMENT_NODE)
344 {
345 $NewNode=$this->myDOMNode->ownerDocument->createElementNS($uri,$nsprefix.':'.$this->myDOMNode->localName);
346 foreach ($this->myDOMNode->attributes as
$n) $NewNode->appendChild(
$n->cloneNode(
true));
347 foreach ($this->myDOMNode->childNodes as
$n) $NewNode->appendChild(
$n->cloneNode(
true));
348 $xpath=new DOMXPath($this->myDOMNode->ownerDocument);
349 $myDOMNodeList=$xpath->query('namespace::*[name()!="xml"]',$this->myDOMNode);
350 foreach ($myDOMNodeList as
$n) $NewNode->setAttributeNS(
'http://www.w3.org/2000/xmlns/',
$n->nodeName,
$n->nodeValue);
351 $this->myDOMNode->parentNode->replaceChild($NewNode,$this->myDOMNode);
352 $this->myDOMNode=$NewNode;
353 }
354 }
356 {
357 if ($this->myDOMNode->parentNode!=null)
358 {
359 if ($this->myDOMNode->nodeType===XML_ATTRIBUTE_NODE) $this->myDOMNode->parentNode->removeAttributeNode($this->myDOMNode);
360 else $this->myDOMNode->parentNode->removeChild($this->myDOMNode);
361 }
362 }
363 protected function _importNode($newnode) {
return $this->myOwnerDocument===$newnode->myOwnerDocument ? $newnode->myDOMNode : $this->myOwnerDocument->myDOMNode->importNode($newnode->myDOMNode,
true);}
365 {
366 if ($aDOMNode==null) return null;
367 switch ($aDOMNode->nodeType)
368 {
369 case XML_ELEMENT_NODE:
return new php4DOMElement($aDOMNode,$aOwnerDocument);
370 case XML_TEXT_NODE:
return new php4DOMText($aDOMNode,$aOwnerDocument);
371 case XML_ATTRIBUTE_NODE:
return new php4DOMAttr($aDOMNode,$aOwnerDocument);
373 default:
return new php4DOMNode($aDOMNode,$aOwnerDocument);
374 }
375 }
376}
378{
379 function data() {
return $this->myDOMNode->data;}
380 function target() {
return $this->myDOMNode->target;}
381}
382
384{
385 function __get($name)
386 {
387 if ($name==='tagname') return '#text';
388 else return parent::__get($name);
389 }
390 function tagname() {
return '#text';}
392}
393
394if (!defined('XPATH_NODESET'))
395{
396 define('XPATH_UNDEFINED',0);
397 define('XPATH_NODESET',1);
398 define('XPATH_BOOLEAN',2);
399 define('XPATH_NUMBER',3);
400 define('XPATH_STRING',4);
401
402
403
404
405
406}
407
409{
412 public $type=XPATH_UNDEFINED;
415 {
416 if (!isset($aDOMNodelist)) return;
417 elseif (is_object($aDOMNodelist)||is_array($aDOMNodelist))
418 {
419 if ($aDOMNodelist->length>0)
420 {
421 $this->myDOMNodelist=$aDOMNodelist;
422 $this->nodeset=array();
423 $this->type=XPATH_NODESET;
424 $i=0;
426 }
427 }
428 elseif (is_int($aDOMNodelist)||is_float($aDOMNodelist))
429 {
430 $this->type=XPATH_NUMBER;
431 $this->value=$aDOMNodelist;
432 }
433 elseif (is_bool($aDOMNodelist))
434 {
435 $this->type=XPATH_BOOLEAN;
436 $this->value=$aDOMNodelist;
437 }
438 elseif (is_string($aDOMNodelist))
439 {
440 $this->type=XPATH_STRING;
441 $this->value=$aDOMNodelist;
442 }
443 }
444}
445
447{
451 {
452
453 $this->myOwnerDocument=$dom_document->myOwnerDocument;
454 $this->myDOMXPath=new DOMXPath($this->myOwnerDocument->myDOMNode);
455 }
456 function xpath_eval($eval_str,$contextnode=
null)
457 {
458 if (method_exists($this->myDOMXPath,'evaluate')) $xp=isset($contextnode) ? $this->myDOMXPath->evaluate($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->evaluate($eval_str);
459 else $xp=isset($contextnode) ? $this->myDOMXPath->query($eval_str,$contextnode->myDOMNode) : $this->myDOMXPath->query($eval_str);
461 return ($xp->type===XPATH_UNDEFINED) ? false : $xp;
462 }
463 function xpath_register_ns($prefix,$namespaceURI) {
return $this->myDOMXPath->registerNamespace($prefix,$namespaceURI);}
464}
465
466if (extension_loaded('xsl'))
467{
468 function domxml_xslt_stylesheet($xslstring) {return new php4DomXsltStylesheet(DOMDocument::loadXML($xslstring));}
469 function domxml_xslt_stylesheet_doc($dom_document) {return new php4DomXsltStylesheet($dom_document);}
470 function domxml_xslt_stylesheet_file($xslfile) {return new php4DomXsltStylesheet(DOMDocument::load($xslfile));}
471 class php4DomXsltStylesheet
472 {
473 private $myxsltProcessor;
474 function php4DomXsltStylesheet($dom_document)
475 {
476 $this->myxsltProcessor=new xsltProcessor();
477 $this->myxsltProcessor->importStyleSheet($dom_document);
478 }
479 function process($dom_document,$xslt_parameters=array(),$param_is_xpath=false)
480 {
481 foreach ($xslt_parameters as $param=>$value) $this->myxsltProcessor->setParameter('',$param,$value);
483 $myphp4DOMDocument->myDOMNode=$this->myxsltProcessor->transformToDoc($dom_document->myDOMNode);
484 return $myphp4DOMDocument;
485 }
486 function result_dump_file($dom_document,
$filename)
487 {
488 $html=$dom_document->myDOMNode->saveHTML();
491 }
492 function result_dump_mem($dom_document) {return $dom_document->myDOMNode->saveHTML();}
493 }
494}
create_processing_instruction($target, $data='')
create_cdata_section($content)
create_entity_reference($content)
get_elements_by_tagname($name)
dump_mem($format=false, $encoding=false)
create_text_node($content)
create_element_ns($uri, $name, $prefix=null)
create_attribute($name, $value)
dump_file($filename, $compressionmode=false, $format=false)
php4DOMDocument($source, $file=true)
get_elements_by_tagname($name)
set_attribute($name, $value)
add_namespace($uri, $prefix)
get_attribute_node($name)
set_namespace($uri, $prefix=null)
static _newDOMElement($aDOMNode, $aOwnerDocument)
add_namespace($uri, $prefix)
new_child($name, $content)
replace_child($oldnode, $newnode)
insert_before($newnode, $refnode)
php4DOMNodelist($aDOMNodelist)
php4DOMXPath($dom_document)
xpath_register_ns($prefix, $namespaceURI)
const DOMXML_LOAD_SUBSTITUTE_ENTITIES
const DOMXML_LOAD_RECOVERING
const DOMXML_LOAD_DONT_KEEP_BLANKS
const DOMXML_LOAD_VALIDATING
const DOMXML_LOAD_PARSING