"Sam Hobbs" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I am trying to copy the body portion of a HTML file for use in the current >page. I am using PHP 5.0.1. > > I think the following is close but not close enough; nothing gets imported > by importNode. I assume this would be easy if I knew the DOM well enough; > if someone else is then I hope this would be easy enough for them to > either fix or provide something that works. > > > <?php > define("APPLICATION_ROOT", "C:/Apache2/htdocs/"); > $Filename = "Categories.html"; > if (!file_exists(APPLICATION_ROOT.$Filename)) { > print "File $Filename does not exist<br>\n"; > exit; > } > $Document = new DOMDocument(); > $Document->loadHTMLFile(APPLICATION_ROOT.$Filename); > if (!$Document) { > echo "Error loading $Filename<br>\n"; > exit; > } > $NewDocument = new DOMDocument(); > $Body = $Document->getElementsByTagName("body")->item(0); > foreach($Body->getElementsByTagName("*") as $Node) > $NewDocument->importNode($Node, FALSE); > print $NewDocument->saveHTML(); > ?>
Ooops, sorry. I should have searched the archives before posting. I see I need to do an appendChild after importNode. That works if I set deep to TRUE, except I get elements repeated. I am confident I will solve that in a couple of minutes, so I think I am finally done with that portion. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

