もみんなこのコードトロウこの例外と...例外XML + PHP
exception: Fatal error: Uncaught exception 'DOMException' with message 'Not Found Error' in C:\AppServ\www\CpVela\publicidades\delete_pub.php:14 Stack trace: #0 C:\AppServ\www\CpVela\publicidades\delete_pub.php(14): DOMNode->removeChild(Object(DOMElement)) #1 {main} thrown in C:\AppServ\www\CpVela\publicidades\delete_pub.php on line 14
<?php
include "../src/defines.php";
if(!empty($_GET['CDG'])){
$doc = new DOMDocument;
$doc->load(DIR_PUBLICIDADES);
$thedocument = $doc->documentElement;
$list = $thedocument->getElementsByTagName('item');
echo $list->length;
$nodeToRemove = NULL;
foreach ($list as $domElement){
$attrValue = $domElement->getAttribute('numero');
if ($attrValue == $_GET['CDG']) {
$nodeToRemove = $domElement;
$thedocument->removeChild($nodeToRemove); // <<< line 14
$f = fopen(DIR_PUBLICIDADES,'w+');
fwrite($f,$doc->saveXML());
fclose($f);
}
}
if ($nodeToRemove != null){
$thedocument->removeChild($nodeToRemove);
$f = fopen(DIR_PUBLICIDADES,'w+');
fwrite($f,$doc->saveXML());
fclose($f);
}
}
header("location:publicidades.php");
?>
私のコードのXMLは、問題があなたのremoveChildメソッドである
<?xml version="1.0" encoding="utf-8"?>
<publicidades>
<internas>
<item nombre="Tony Roma's" numero="SOL_17" posX="266" posY="229" telefono="" web="" correo="" encargado="" descripcion="" promocion="" ></item>
</internas>
<externas>
</externas>
</publicidades>
が、どのように可能です?もし$ thedocumentが$ doc-> documentElementなら:$ doc-> documentElemntは$ docの子ではありませんか? –
'echo'ループ内の'現在の要素 'の値を参考にしてください。 –
echo $ attrValue; //結果= SOL_17 –