Adding new xml element with hpricot

I’ve got a lot of xml files that look something like this:

some text some text an integer ... an integer ... more stuff

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.