PHP Doku:: Deletes node - function.domnode-unlink-node.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzXML-ManipulationDOM-XMLDOM-XML-FunktionenDomNode->unlink_node

Ein Service von Reinhard Neidl - Webprogrammierung.

DOM-XML-Funktionen

<<DomNode->set_namespace

DomProcessingInstruction->data>>


3 BenutzerBeiträge:
- Beiträge aktualisieren...
dajohny at gmail dot com
3.11.2008 10:00
<?xml version="1.0"?>
<galleries>
  <gallery title="test" intro="">
    <image/>
    <image/>
  </gallery>
  <gallery title="test1" intro="">
    <image/>
    <image/>
    <image/>
    <image/>
   </gallery>
  <gallery title="test2" intro="">
    <image/>
    <image/>
    <image/>
    <image/>
  </gallery>
</galleries>

<?php
$dom
= domxml_open_file($xmlfilename, DOMXML_LOAD_DONT_KEEP_BLANKS)
$x = $dom->get_elements_by_tagname('youtagname');

for(
$i=0;$i<count($x);$i++)
{
   
// to remove a particular node by finding the
   
if($x[$i]->get_attribute('title')=="test1")
    {
       
$remnode $x[$i]->node_name();
       
$x[$i]->unlink_node($remnode);
       
$dom->dump_file($xmlfilename, false, true);
    }
}

// Final xml will be like this:
?>

<?xml version="1.0"?>
<galleries>
  <gallery title="test" intro="">
    <image/>
    <image/>
  </gallery>
  <gallery title="test2" intro="">
    <image/>
    <image/>
    <image/>
    <image/>
  </gallery>
</galleries>

Njoi :)
starloran at hotmail dot com
1.10.2004 15:46
I tried to use unlink_node to delete a node, but it never worked.
However, you can delete a node with this:

function delNode($node){
                   $nud=$node->parent_node();
                   $nud->remove_child($node);
}
phpnotes AT no Spam dot phillfox.net
22.11.2002 23:07
Just like dump_node*, this method requres the node as an argument.
Like this:
      $removeThis = $dom->get_element_by_id ('26');
      $unlinked = $removeThis->unlink_node($removeThis);

In the example above, $unlinked seems to be NULL.

I'm using 4.3.0-dev (build: Nov 14 2002 10:13:12) in Module mode on Apache/1.3.24 - Win2000.

* see: http://www.php.net/manual/en/function.domnode-dump-node.php



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)