From: Phrogz Date: 2007-11-27T05:25:01+09:00 Subject: Re: How to map XML attributes On Nov 26, 9:37 am, Trans 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: > > > > HTML Content > > > > 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.: ... 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] #=> ...