<p>I have an XML document with a DTD, and would love to be able to access the XML model, something like this:</p>

<pre><code>title = Thing.Items[0].Title
</code></pre>

<p>Is there a way, in Ruby, to generate this kind of object model based on a DTD? Or am I stuck using REXML?</p>

<p>Thanks!</p>

[{'answer_id': 28557, 'author': 'John Duff', 'author_id': 3041, 'author_profile': 'https://Stackoverflow.com/users/3041', 'pm_score': 2, 'selected': False, 'text': "<p>if you include the active_support gem (comes with rails) it adds the method from_xml to the Hash object.  You can then call Hash.from_xml(xml_content) and it'll return a hash that you can use to access the data.</p>\n\n<p>I don't know of an easy way to map an xml to an object, but you could create a wrapper class that delegates the method calls to the underlying hash which holds the data.</p>\n"}, {'answer_id': 28562, 'author': 'TonyLa', 'author_id': 1295, 'author_profile': 'https://Stackoverflow.com/users/1295', 'pm_score': 1, 'selected': True, 'text': '<p>You can use the ruby version of xml-simple.</p>\n\n<p>You shouldn\'t need to install the gem as I believe it\'s already installed with rails.\n<a href="http://xml-simple.rubyforge.org/" rel="nofollow noreferrer">http://xml-simple.rubyforge.org/</a></p>\n'}, {'answer_id': 1462093, 'author': 'David Richards', 'author_id': 177363, 'author_profile': 'https://Stackoverflow.com/users/177363', 'pm_score': 1, 'selected': False, 'text': "<p>I know this question was asked a while back, but if you want the true Thing.Items[0].Title type format, all you need to do is use OpenStruct.</p>\n\n<pre><code>require 'rubygems'\nrequire 'activesupport' # For xml-simple\nrequire 'ostruct' \n\nh = Hash.from_xml File.read('some.xml')\no = OpenStruct.new h\no.thing.items[0].title \n</code></pre>\n"}]
['https://Stackoverflow.com/questions/28293', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/722/']