I've got a lot of xml files that look something like this: <preferences> <pref_1>some text</pref_1> <pref_2>some text</pref_2> <pref_3>an integer</pref_3> ... <pref_of_interest>an integer</pref_of_interest> ... <pref_n>more stuff</pref_n> </preferences> There could be no "pref_of_interest" fields or there could be several. What I need to do is the following: 1. If there are no pref_of_interest fields, or there's already a pref_of_interest set to the desired value, leave the file untouched. 2. If there are prefs_of_interest and none contain the required value, add a new pref_of_interest element with the required value in. I have not had much success with hpricot past parsing the file. Can anyone suggest the proper way to add the new element? Thanks.
on 2009-03-16 12:21