require 'rexml/document'
include REXML
xml =<
4
7
5
3
XML
doc = Document.new xml
XPath.match(doc.root, 'records/item/attribute::id').max_by &:value
=> id='4'
XPath.match(doc.root, 'records/item/attribute::id').min_by &:value
=> id='1'
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/uMmsXhJnUzY/10961