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

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
hannnndy
Forum Contributor
Posts: 131
Joined: Sat Jan 12, 2008 2:09 am
Location: Iran>Tehran
Contact:

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

Post 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
dayyanb
Forum Commoner
Posts: 46
Joined: Wed Jan 23, 2008 12:34 am

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

Post 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"?
Post Reply