xml den eleman çıkarmak

0 Cevap php

in my xml file i want to remove record element according to title My xml file is

<?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>

ve benim php dosya

        <?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(); 
                      ?>

o aşağıdaki hatayı veriyor: -

Ölümcül hata: iletisiyle yakalanmamış istisna 'DOMException' D 'Hatası Bulunamadı': \ wamp \ www \ funkeymusic \ admin \ update_video.php: 22 Stack trace: # 0 D: \ wamp \ www \ funkeymusic \ admin \ update_video. php (22): DOMNode-> removeChild (Object (DOMElement)) # 1 {main} D atılmış: \ wamp \ www \ funkeymusic \ admin \ update_video.php hattında 22

0 Cevap