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? Quote Link to comment 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()); Quote Link to comment 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.