23 function staticxmlerror(
int $errno,
string $errstr, ?
string $errfile = null, ?
int $errline = null, ?array $errcontext = null,
bool $ret =
false)
25 static $errs = array();
27 $tag =
'DOMDocument::validate(): ';
28 $errs[] = str_replace($tag,
'', $errstr);
40 define(
'DOMXML_LOAD_PARSING', 0);
60 return $xpath_context->
query($eval_str, $contextnode);
74 $this->myDOMAttr = $aDOMAttr;
79 return $this->myDOMAttr->name;
84 return $this->myDOMAttr->specified;
89 return $this->myDOMAttr->value;
99 parent::php4DOMNode($aDOMCDATASection);
100 $this->myDOMCDATASection = $aDOMCDATASection;
106 public $success = null;
107 public string $error =
"";
115 set_error_handler(
'staticxmlerror');
116 $old = ini_set(
'html_errors',
false);
119 $this->myDOMDocument =
$source;
130 ini_set(
'html_errors', $old);
131 restore_error_handler();
135 foreach ($this->error_arr as $error) {
136 $error = str_replace(
"DOMDocument::loadXML():",
"", $error);
137 $this->error .= $error .
"<br />";
149 unset($this->myDOMDocument);
161 $str = $this->myDOMDocument->saveXML($node->myDOMNode);
166 public function validate(&$error,
bool $throw =
false)
170 $ok = $this->myDOMDocument->validate();
177 $error = array(array(
"0",
"Unknown Error"));
179 if (function_exists(
"libxml_get_last_error")) {
180 $err = libxml_get_last_error();
182 if (is_object($err)) {
183 $error = array(array($err->code, $err->message));
192 $myAttr = $this->myDOMDocument->createAttribute(
$name);
193 $myAttr->value = $value;
210 return new php4DOMElement($this->myDOMDocument->createElement($name));
215 return new php4DOMNode($this->myDOMDocument->createTextNode($content));
225 return $this->myDOMDocument->save(
$filename);
230 $r = $this->myDOMDocument->saveXML();
236 $myDOMNodeList = $this->myDOMDocument->getElementsByTagName(
$name);
239 while ($node = $myDOMNodeList->item(
$i)) {
249 return $this->myDOMDocument->saveHTML();
260 return $this->myDOMNode->getAttribute(
$name);
270 $myDOMNodeList = $this->myDOMNode->getElementsByTagName(
$name);
273 while ($node = $myDOMNodeList->item(
$i)) {
283 return $this->myDOMNode->hasAttribute(
$name);
288 return $this->myDOMNode->removeAttribute(
$name);
293 return $this->myDOMNode->setAttribute(
$name, $value);
298 return $this->myDOMNode->tagName;
307 $text = str_replace(
"<",
"<", $text);
308 $text = str_replace(
">",
">", $text);
309 $text = str_replace(
"&",
"&", $text);
312 $text_node->appendData($text);
313 if (is_object($this->myDOMNode->firstChild)) {
314 $this->myDOMNode->replaceChild($text_node, $this->myDOMNode->firstChild);
316 $this->myDOMNode->appendChild($text_node);
323 $text_node = $this->myDOMNode->firstChild;
325 if (is_object($text_node)) {
326 return $text_node->textContent;
335 parent::unlink_node($aDomNode);
348 $this->myDOMNode = $aDomNode;
356 $doc = $this->myDOMNode->ownerDocument;
358 $newnode->myDOMNode = $doc->importNode($newnode->myDOMNode,
true);
360 return new php4DOMElement($this->myDOMNode->appendChild($newnode->myDOMNode));
369 return $this->
set_content($newnode->myDOMNode->textContent);
374 return new php4DOMElement($this->myDOMNode->parentNode->appendChild($newnode->myDOMNode));
380 $myDOMNodeList = $this->myDOMNode->attributes;
383 if (is_object($myDOMNodeList)) {
384 while ($node = $myDOMNodeList->item(
$i)) {
395 $myDOMNodeList = $this->myDOMNode->childNodes;
398 while ($node = $myDOMNodeList->item(
$i)) {
416 if (!is_object($aDomNode)) {
421 $parent = $aDomNode->myDOMNode->parentNode;
422 if (is_object($parent)) {
423 $parent->removeChild($aDomNode->myDOMNode);
439 return $this->myDOMNode->textContent;
444 return $this->myDOMNode->hasAttributes();
449 return $this->myDOMNode->hasChildNodes();
456 $doc = $this->myDOMNode->ownerDocument;
457 $newnode->myDOMNode = $doc->importNode($newnode->myDOMNode,
true);
460 $mynewnode = $newnode->myDOMNode;
461 $myrefnode = $refnode->myDOMNode;
463 $domel = $mydomnode->insertBefore($mynewnode, $myrefnode);
464 }
catch (DOMException $exception) {
466 $mydomnode = $this->myDOMNode->parentNode;
467 $domel = $mydomnode->insertBefore($mynewnode, $myrefnode);
476 $last = $this->myDOMNode->lastChild;
478 if (is_object($last)) {
488 $next = $this->myDOMNode->nextSibling;
490 if (is_object($next)) {
500 return $this->myDOMNode->localName ??
"";
502 return $this->myDOMNode->nodeName ??
"";
508 return $this->myDOMNode->nodeType;
513 return $this->myDOMNode->nodeValue;
519 $parent = $this->myDOMNode->parentNode;
521 if (is_object($parent)) {
531 $prev = $this->myDOMNode->previousSibling;
533 if (is_object($prev)) {
542 return new php4DOMElement($this->myDOMNode->removeChild($oldchild->myDOMNode));
547 return new php4DOMElement($this->myDOMNode->replaceChild($oldchild->myDOMNode, $newnode->myDOMNode));
552 $this->myDOMNode->textContent = $text;
553 return $this->myDOMNode->textContent;
564 $this->myDOMNodelist = $aDOMNodelist;
565 $this->nodeset = array();
567 while ($node = $this->myDOMNodelist->item(
$i)) {
586 $this->myDOMXPath =
new DOMXPath($dom_document->myDOMDocument);
596 return $this->myDOMXPath->registerNamespace($prefix, $namespaceURI);
xpath_eval(php4DOMXPath $xpath_context, string $eval_str, $contextnode=null)
xpath_register_ns($prefix, $namespaceURI)
create_element(string $name)
set_attribute($name, $value)
__construct($aDOMCDATASection)
dump_mem($format=false, $encoding=false)
DOMDocument $myDOMDocument
__construct($dom_document)
dump_file($filename, $compressionmode=false, $format=false)
get_elements_by_tagname($name)
xpath_new_context($dom_document)
create_cdata_section($content)
get_elements_by_tagname($name)
domxml_open_mem($str, $mode=0, &$error=null)
domxml_open_file($filename)
validate(&$error, bool $throw=false)
__construct($aDOMNodelist)
insert_before($newnode, $refnode)
unlink_node($aDomNode="")
create_attribute($name, $value)
node_name($a_local=false)
staticxmlerror(int $errno, string $errstr, ?string $errfile=null, ?int $errline=null, ?array $errcontext=null, bool $ret=false)
__construct($source, $file=true, $a_mode=0)
create_text_node($content)
replace_child($oldnode, $newnode)