On Nov 26, 9:37 am, Trans <transf... / gmail.com> wrote: > I'm working on a DSL that maps XML <=> Object, and I'm stuck on where > to store tag attributes. Do attributes belong to the tag or to the > content? > > For example: > > <foo> > <bar xmlns="http://..." type="html"> > HTML Content > </bar> > </foo> > > In mapping this to an object, lets say: > > foo.bar #=> "HTML Content" > > Does is make sense to ask: > > foo.bar.attributes #=> { 'xmlns'=>..., 'type'=>... } > > or should the attributes be tied to the "attributation" of foo, so: > > foo.attributes(:bar) #=> { 'xmlns'=>..., 'type'=>... } > > The 'type' attribute makes me think the first makes the most sense, > but the 'xmlns' makes me think the later. I don't share your opinion on xmlns implying the latter. All attributes are attributes of an element; the first totally makes sense. How would you get the attributes of the rootmost element, e.g.: <root id="page3"> ... </root> Just attributes( :root )? Bleah, I say. If I were writing an XML-like DOM, I'd use dot notation (method call) for the child axis and [] notation for the attributes axis. foo.bar[:type] #=> ...