ToonMariner Posted February 1, 2007 Share Posted February 1, 2007 need some fast help with manipulating xml files. I have an rss feed like so <?xml version="1.0" encoding="iso-8859-1" ?> <?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/xml/xsl/nolsol.xsl" ?> <rss version="2.0"> <channel> <title>Mysite</title> <link>http://www.mysite.co.uk/news</link> <feed>http://www.mysite.co.uk/xml/news.xml</feed> <description>News from mysite</description> <category>Sport</category> <copyright>2007 mysite. All rights reserved.</copyright> <language>en</language> <managingEditor>[email protected]</managingEditor> <item> <title>50 Years and Still Young</title> <link>http://www.mysite.co.uk/news/2007/1/1</link> <description>mysite are clebrating 50 years.</description> <pubDate>1 Jan 2007 09:00:00 GMT</pubDate> <author>Rob Charlton</author> <guid isPermaLink="false">http://www.mysite.co.uk/news/2007/1/1</guid> </item> <item> <title>Footy Rules</title> <link>http://www.www.waring-netts.co.uk/news/2006/10/25</link> <description>Football is the biggest game on earth.</description> <pubDate>25 Oct 2006 09:00:00 GMT</pubDate> <author>Someone</author> <guid isPermaLink="false">http://www.mysite.co.uk/news/2006/10/25</guid> </item> <item> <title>A New House for Gran</title> <link>http://www.mysite.co.uk/news/2006/10/15</link> <description>Gran has a new house.</description> <pubDate>15 Oct 2006 09:00:00 GMT</pubDate> <author>Mum</author> <guid isPermaLink="false">http://www.mysite.co.uk/news/2006/10/15</guid> </item> </channel> </rss> All I need to do is add a new child node 'item' and if the number of childnodes of channel called item is greater than 50 remove them. here is what I have tried so far with limited (no) success.... $file = $_SERVER['DOCUMENT_ROOT'] . '/xml/test.xml'; $dom = domxml_open_file($file); $elements = $dom->get_elements_by_tagname ('item'); $nonodes = count($elements); if ( $nonodes > 4 ) { $remove = $elements[$nonodes - 1]; $child = $dom->dump_node($remove); } $element = $elements[0]; $newnode = $element->insert_before($element, $element); $children = $newnode->children(); $attr = $children[1]->set_attribute("align", "left"); $xmlfile = $dom->dump_mem(true); echo htmlentities($xmlfile); now all that is doing is replacing the first item node with a line!!!!! I need some kind fo loop to remove child nodes as there could be a situation where a few nodes get added manually so teh script needs to remove all nodes after the 50th one. If anyone can help I woudl be very greatful. Link to comment https://forums.phpfreaks.com/topic/36637-basic-management-of-rss-fedd/ Share on other sites More sharing options...
ToonMariner Posted February 2, 2007 Author Share Posted February 2, 2007 #Bump# Link to comment https://forums.phpfreaks.com/topic/36637-basic-management-of-rss-fedd/#findComment-175292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.