Ruby offers define_method as a private method on modules and classes for defining new instance methods. However, the 'body' of the method must be a Proc or another existing method.
One way to create a method from raw string data is to use eval to create a Proc from the code:
xml = <<ENDXML
...