drb0901500211
drb0901500211
2018-01-18 21:37

php中的php删除元素

已采纳

I'm trying to use php to delete an xml element but it doesn't work. I tried some different code but no one works. I would also like to use cookies to get element in the future. Can you suggest me what I have to do ? I'm not expert and for this I'm in difficulty.

Here the code:

    <?php

$dom = new DOMDocument();
$dom->load("Dati.xml");

$matchingElements = $dom->getElementsByTagName("Matematica");
$totalMatches     = $matchingElements->length;

$elementsToDelete = array();

    $elementsToDelete[] = $matchingElements->item(0);

foreach ( $elementsToDelete as $elementToDelete ) {
    $elementToDelete->parentNode->removeChild($elementToDelete);
}

$dom->save($xmlFileToLoad);
echo  "<script type='text/javascript'>";
   echo "window.close();";
   echo "</script>";
echo "Puoi chiudere questa pagina";

?>

Here the xml:

 <?xml version="1.0" encoding="UTF-8"?>
<document>
<Informatica>
<nome>aaaa</nome>
<classe>3C</classe>
<titolo>Informatica</titolo>
<materia>Informatica</materia>
<ISBN>123456789101112</ISBN>
<prezzo>12</prezzo>
<autori>tizio</autori>
<contatto>nanni-lombardo1@hotmail.it</contatto>
<codice>123456</codice>
</Informatica>
<Matematica>
<nome>bbb</nome>
<classe>3C</classe>
<titolo>math</titolo>
<materia>Matematica</materia>
<ISBN>123456789101112</ISBN>
<prezzo>12</prezzo>
<autori>tizio</autori>
<contatto>nanni-lombardo1@hotmail.it</contatto>
<codice>123456</codice>
</Matematica>

</document>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答