No need to be hardcoded, you can use a list and you can use the in
operator:
xml = '''<div>
<div class="header">header div</div>
<div class="body">body div</div>
<span class="footer">footer span</span>
</div>
'''
node = new XmlSlurper().parseText xml
// the element's classes we want
classes = ['header', 'body']
contents = node.breadthFirst().findAll { it.@class in classes }*.text()
assert contents == ['header div', 'body div']