특정 속성이있는 확장 DOMElement 객체를 모든 속성을 사용하여 만든 DOMDocument로 가져 오는 경우 실제로 손실되지 않습니다. 다른 문서에 대해 새 노드가 만들어지고 DOMElement 클래스의 값만 새 노드에 복사됩니다. 가져온 요소에서 속성을 계속 사용할 수있는 가장 좋은 방법은 무엇입니까?확장 DOMElement 객체가 다른 문서로 가져올 때 해당 속성을 잃습니다.
<?php
class DOMExtendedElement extends DOMElement {
private $itsVerySpecialProperty;
public function setVerySpecialProperty($property) {$this->itsVerySpecialProperty = $property;}
}
// First document
$firstDocument = new DOMDocument();
$firstDocument->registerNodeClass("DOMElement", "DOMExtendedElement");
$elm = $firstDocument->createElement("elm");
$elm->setVerySpecialProperty("Hello World!");
var_dump($elm);
// Second document
$secondDocument = new DOMDocument();
var_dump($secondDocument->importNode($elm, true)); // The imported element is a DOMElement and doesn't have any other properties at all
// Third document
$thirdDocument = new DOMDocument();
$thirdDocument->registerNodeClass("DOMElement", "DOMExtendedElement");
var_dump($thirdDocument->importNode($elm, true)); // The imported element is a DOMExtendedElement and does have the extra property but it's empty
?>
이
결국 목표는 무엇입니까? XML 저장? – Shikiryu