在我的XML文件中刪除元素,我想根據標題去掉記錄元素 我的XML文件是從XML
<?xml version="1.0"?>
<gallerylist>
<record>
<movie>videos/Avatar_HD.flv</movie>
<title>Title:</title>
<desc>Description</desc>
<preview>videos/previews/avatar.jpg</preview>
<imgplaylist>videos/imgplaylist/p1.jpg</imgplaylist>
<category>Category</category>
</record>
<record>
<movie>videos/The_Princess_And_The_Frog_HD.flv</movie>
<title></title>
<desc>fdgdd</desc>
<preview>videos/previews/frog.jpg</preview>
<imgplaylist>videos/imgplaylist/p4.jpg</imgplaylist>
<category>Category1</category>
</record>
<record>
<movie>videos/Prince_of_Persia_The_Sands_of_Time_HD.flv</movie>
<title>Title:2</title>
<desc>xzcXZ</desc>
<preview>videos/previews/sandsoftime.jpg</preview>
<imgplaylist>videos/imgplaylist/p2.jpg</imgplaylist>
<category>Category2</category>
</record>
<record>
<movie>videos/Sherlock_Holmes_HD.flv</movie>
<title>Title:4</title>
<desc>dfgdf</desc>
<preview>videos/previews/sherlock.jpg</preview>
<imgplaylist>videos/imgplaylist/p7.jpg</imgplaylist>
<category>Category4</category>
</record>
</gallerylist>
和我的PHP文件是
<?php
$doc = new DOMDocument;
$doc->load('playlist.xml');
$thedocument = $doc->documentElement;
$list = $thedocument->getElementsByTagName('title');
$nodeToRemove = null;
foreach ($list as $domElement){
$attrValue = $domElement->nodeValue;
if ($attrValue == 'Title:4') {
$nodeToRemove = $domElement;
}
}
if ($nodeToRemove != null)
$thedocument->removeChild($nodeToRemove);
$doc->saveXML();
?>
它提供了以下錯誤: -
致命錯誤:在D:\ wamp \ www \ funkeymusic \ admin \ update_video.php:22堆棧跟蹤:#0 D:\ wamp \ www \ funkeymusic \中找到未找到異常'DOMException'管理員\ updat第22行D:\ wamp \ www \ funkeymusic \ admin \ update_video.php中拋出的DOMNode-> removeChild(Object(DOMElement))#1 {main}
但它不是從文件中刪除 – Rajanikant 2010-07-23 12:10:49
@Rajanikant:它做了什麼呢? – Tomalak 2010-07-23 12:15:00
它顯示空白頁面或磨打印 – Rajanikant 2010-07-23 12:19:53