Skip to content

Instantly share code, notes, and snippets.

@mojodna
Created December 10, 2008 00:33
Show Gist options
  • Save mojodna/34163 to your computer and use it in GitHub Desktop.
Save mojodna/34163 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<rsp stat="fail">
<err code="11" msg="Something bad happened" />
</rsp>
require 'rubygems'
require 'happymapper'
require 'pp'
class Error
include HappyMapper
attribute :code, Integer
attribute :message, String
end
class Rsp
include HappyMapper
# NOTE: tag "/rsp" helps, but doesn't seem necessary
attribute :stat, String
element :err, Error
end
error = File.read("error.xml")
pp Rsp.parse(error) # => []
pp Rsp.parse(error, :single => true) # => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment