prometheos Posted April 15, 2010 Share Posted April 15, 2010 Hi, i have an xml in the following format (ratings as root). I want to increment the 'stars' attribute. <ratings stars="0"> <rating> <experience></experience> <comment></comment> </rating> </ratings> Here's what i have to increment the stars attribute, but it's not working? ($experience is a posted variable) $dom = new DOMDocument(); $dom->load($forfilename); if($experience=="Positive"){ $val += 1; $dom->setAttribute('stars', $val); }else{ $val -= 1; $dom->setAttribute('stars', $val); } $dom->save($forfilename); Can any1 help me :S this should work right? What am i missing? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/198593-simple-dom-xml/ Share on other sites More sharing options...
ChemicalBliss Posted April 15, 2010 Share Posted April 15, 2010 Check if th file is loading correctly: echo $dom->saveXML(); Use that before and after the if condition. Also, are you using some special class, i dont see a 'setAttribute' method listed in the php manual for the default DOMDocument class. -cb- Link to comment https://forums.phpfreaks.com/topic/198593-simple-dom-xml/#findComment-1042128 Share on other sites More sharing options...
prometheos Posted April 15, 2010 Author Share Posted April 15, 2010 Thanks for the reply, i realised that about the document class so i changed it to this and its working now! thanks here's what i have : $xmlDoc = new DOMDocument(); $xmlDoc->load($filename); if($experience=="Positive"){ $searchNode = $xmlDoc->getElementsByTagName("ratings"); $val += 1; $ratings = $searchNode->item(0); $ratings->setAttribute('stars', $val); } Check if th file is loading correctly: echo $dom->saveXML(); Use that before and after the if condition. Also, are you using some special class, i dont see a 'setAttribute' method listed in the php manual for the default DOMDocument class. -cb- Link to comment https://forums.phpfreaks.com/topic/198593-simple-dom-xml/#findComment-1042130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.