Alex-Grim Posted December 26, 2007 Share Posted December 26, 2007 Hey guys, is there a way to remove an element with simplexml? I don't see it in their documentation. If so, how would i go about doing it? Or you could just point me towards documentation. Thanx Quote Link to comment https://forums.phpfreaks.com/topic/83181-simplexml-removechil/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2007 Share Posted December 26, 2007 You could try unset() on the element. Quote Link to comment https://forums.phpfreaks.com/topic/83181-simplexml-removechil/#findComment-423111 Share on other sites More sharing options...
Alex-Grim Posted December 26, 2007 Author Share Posted December 26, 2007 After trying this pice of code, i get mixed results. I get the string correct, but the IF statement fails for some reason? Here's the code, then the output: $xml2 = new SimpleXMLElement("../sitemap.xml",null,true); foreach ($xml2->url as $loc){ if ($loc->loc == "http://LinuxIntro.com?action=".$qx1[0]."&name=".$_GET['name']){ echo "I found IT!<br/>"; }else{ echo "Not it!<br/>"; echo "http://LinuxIntro.com?action=".$qx1[0]."&name=".$_GET['name']."<br/>"; echo $loc->loc . "<br/>"; } } Which returns: Not it! http://LinuxIntro.com?action=ShowContent&name=aaaaaaaaaaaaaa http://LinuxIntro.com/ Not it! http://LinuxIntro.com?action=ShowContent&name=aaaaaaaaaaaaaa http://LinuxIntro.com?action=ShowContent&name=aaaaaaaaaaaaaa What i am attempting to accomplish, is to remove a page from my sitemap, when i delete it from the database. I have the opposite effect in place already; when i create a new page via my admin console i wrote, it adds that page to my sitemap. Now i need the reverse done: when i delete a page from the DB, it is also removed from the sitemap. ===EDIT=== Also, i guess, just for clarity, i should add the contents of my xml file: <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"> <url> <loc>http://LinuxIntro.com/</loc> <changefreq>daily</changefreq> <priority>0.3</priority> </url> <url> <loc>http://LinuxIntro.com?action=ShowContent&name=aaaaaaaaaaaaaa</loc> <changefreq>daily</changefreq> <priority>0.3</priority> </url> </urlset> Thanx Quote Link to comment https://forums.phpfreaks.com/topic/83181-simplexml-removechil/#findComment-423120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.