Page 1 of 1

[SOLVED] node->removeChild(); not working in our php 5.2.5

Posted: Sat Feb 02, 2008 11:08 pm
by hannnndy
i do not know why but it is not working

Code: Select all

 
    public function delete($x)
    {
        //echo("in function delete");
        $dom = new DomDocument;
        $dom->validateOnParse = true;  // important, so we get the id listings from the dtd 
        $dom->load("sampleLink.xml"); 
        $xpath = new DomXPath($dom);
        
        $result = $xpath->query($x);
        $linkNode = $result->item(0);
        [b]$dom->getElementsByTagName("menu")->item(0)->removeChild($linkNode);[/b]
        $dom->save("sampleLink.xml");
    }
 
error occurred at the bold line i do not know why?
the error is

Warning: DOMNode::removeChild() expects parameter 1 to be DOMNode, null given in



we should use this

Code: Select all

$parentNode->removeChild($node);    //removes the childNode

Re: [SOLVED] node->removeChild(); not working in our php 5.2.5

Posted: Mon Feb 04, 2008 6:51 pm
by dayyanb

Code: Select all

 
    public function delete($x)
    {
        //echo("in function delete");
        $dom = new DomDocument;
        $dom->validateOnParse = true;  // important, so we get the id listings from the dtd 
        $dom->load("sampleLink.xml"); 
        $xpath = new DomXPath($dom);
        
        $result = $xpath->query($x);
        $linkNode = $result->item(0);
        [b]$dom->getElementsByTagName("menu")->item(0)->removeChild($linkNode);[/b]
        $dom->save("sampleLink.xml");
    }
 
Have you tried checking what is in "$result"?