bdee1 Posted January 23, 2009 Share Posted January 23, 2009 i am using simpleXML to parse and update the contents of an xml file based on user input. my xml structure looks liek this: <linkCollection> <linkGroup id="1" title="Photoshop"> <linkItem id="2"> <title></title> <description></description> <url></url> </linkItem> <linkItem id="4"> <title></title> <description></description> <url></url> </linkItem> </linkGroup> </linkCollection> i want the user to be able to edit the title attribute of the linkGroup node. i know that i could drop the node and then rebuild it with the updated values but since the linkGroup node could have many children, it woudl be nice if i coudl just update the title attribute and then save the file. how could i go about doing that? Link to comment https://forums.phpfreaks.com/topic/142161-using-simplexml-to-edit-a-node-attribute/ Share on other sites More sharing options...
bdee1 Posted January 23, 2009 Author Share Posted January 23, 2009 nevermind - it was way simpler than i thought. #CREATING THE HANDLER $xml = simplexml_load_file(SITEROOT.'/data/file.xml'); #loop through the LinkGroups to find the one we're looking for foreach($xml->linkCollection->linkGroup as $linkGroup) { if ($linkGroup['id'] == $passed_groupID) { $linkGroup['title'] = $passed_title; break; } } #WRITE THE RESULTS BACK TO THE XML FILE file_put_contents(SITEROOT.'/data/file.xml', $xml->asXml()); Link to comment https://forums.phpfreaks.com/topic/142161-using-simplexml-to-edit-a-node-attribute/#findComment-744702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.