† Stratos †
Новичок
Wrong Document Error (XML+PHP5)
есть код
короче клонирование удачно происходит, но исключение все равно "вылетает".
подскажите плиз где тут не так?
=======================================
может будет попроще, если я скажу, что код был написан под domxml. и я его переписываю под dom стандарт.
код был следующий (работал корректно)
-~{}~ 16.05.06 12:03:
не думал, что мне здесь не помогут.
но проблема решена.
есть код
PHP:
$dom_res1 = new DomDocument();
$dom_res1->load($file_asi1);
if(!@file_exists($file_asi2)) {
$dom_res2 = new DomDocument();
$dom_res2->appendChild($dom_res2->createElement("questestinterop"));
} else {
$dom_res2 = new DomDocument();
$dom_res2->load($file_asi2);
}
$parent=$dom_res1;
$e_section=find_element($parent,'section','ident',$section_id);
$e_section2=$e_section->ownerDocument;
$root2=$dom_res2;
$parent2=find_element($root2,'questestinterop');//находит элемент 'questestinterop' и делает переменную объектом DOMElement
$temp=$dom_res2->createElement('a1');
try {
$copy = $dom_res2->importNode($e_section,1);
echo "yo: ".$copy->nodeName;
$e_section2=$parent2->insertBefore($e_section, $copy);
} catch (Exception $e) {
echo "<pre>";
echo $e; die();
}
print_r($e_section2);die();
подскажите плиз где тут не так?
=======================================
может будет попроще, если я скажу, что код был написан под domxml. и я его переписываю под dom стандарт.
код был следующий (работал корректно)
PHP:
$dom_res1=@domxml_open_file($file_asi1);
if(!file_exists($file_asi2))
{
$dom_res2 = domxml_new_doc("1.0");
$dom_res2->append_child($dom_res2->create_element("questestinterop"));
}
else
{
$dom_res2=@domxml_open_file($file_asi2);
}
$root=$dom_res1->root();
$parent=$root;
$e_ass=find_element($root,'assessment','ident',$test_id);
$e_ass2=$e_ass->owner_document();
$root2=$dom_res2->root();
$parent=$root2;
$temp=$dom_res2->create_element('1');
$e_ass2=$parent->insert_before ( $e_ass, $temp);
$e_ass2=$parent->append_child($e_ass2);
$temp->unlink_node();
не думал, что мне здесь не помогут.
но проблема решена.
PHP:
$dom_res1 = new DomDocument();
$dom_res1->load($file_asi1);
if(!@file_exists($file_asi2)) {
$dom_res2 = new DomDocument();
$dom_res2->appendChild($dom_res2->createElement("questestinterop"));
} else {
$dom_res2 = new DomDocument();
$dom_res2->load($file_asi2);
}
$parent=$dom_res1;
$e_section=find_element($parent,'section','ident',$section_id);
$e_section2=$e_section->ownerDocument;
$root2=$dom_res2;
$parent=find_element($root2,'questestinterop');
$temp=$dom_res2->createElement('a1');
$temp=$parent->appendChild($temp);
$copy_from_dom1_section = $dom_res2->importNode($e_section, 1);
$new_section = $parent->insertBefore($copy_from_dom1_section, $temp);
$new_section = $parent->appendChild($new_section);
$temp->parentNode->removeChild($temp);