FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » PHP5 DOM extension - using firstChild
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
PHP5 DOM extension - using firstChild [message #177541] Sun, 08 April 2012 21:17 Go to previous message
Denis[1] is currently offline  Denis[1]
Messages: 2
Registered: April 2012
Karma:
Junior Member
I have a script that uses xpath to retrieve an element using the PHP5
DOM extension and I want to delete all of the children of this
element. I use hasChildNodes and firstChild to do this. Here is my
script:

$xpath = new DOMXPath($doc);
$query = "//invitee[@id=\"$id\"]";
$nodelist = $xpath->query($query);
$hndChild = $nodelist->item(0);
print get_class($hndChild);

while($hndChild->hasChildNodes()) {
print $hndChild->firstChild->nodeValue;
$toGo = $hndChild->firstChild(); <-- failing statement
$hndChild->removeChild($toGo);
}

My get_class print verifies that I have a DOMElement. I have a print
statement that prints the nodeValue of the firstChild as the first
statement of my while loop and I get the correct result. But then my
next statement fails (on the first iteration) with this error message:

Fatal error: Call to undefined method DOMElement::firstChild() in
save.php on line 51

I can't figure out why this second firstChild statement (failing
statement above) fails. Seems like if firstChild is an undefined
method then the firstChild->nodeValue would also fail but it doesn't.
Can anyone enlighten me on what might be going on here?

Denis
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: variable path lose slashs when used in an alert
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 11:12:47 GMT 2024

Total time taken to generate the page: 0.03990 seconds