I am using the XML builder and I am frustrated by the lack of being able to use variables to define the names of XML elements I want to be able to do this (in actionname.xml.builder) ... element_name = "Tag" xml.element_name("Brandon") ... ACTUAL OUTPUT ... <element_name>Brandon</element_name> ... DESIRED OUTPUT ... <Tag>Brandon</Tag> ... Does anyone know how I could achieve the desired output using only the xml builder? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 21, 10:26 pm, Brandon <bemat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> DESIRED OUTPUT > ... > <Tag>Brandon</Tag> > ... > > Does anyone know how I could achieve the desired output using only the > xml builder?have a look at the tag! method Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
try xml.instruct! xml.data do xml.tag "Brandon" end this will give you: <data> <tag>Brandon</tag> </data> Cheers On Jul 21, 5:26 pm, Brandon <bemat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using the XML builder and I am frustrated by the lack of being > able to use variables to define the names of XML elements > > I want to be able to do this (in actionname.xml.builder) > ... > element_name = "Tag" > xml.element_name("Brandon") > ... > > ACTUAL OUTPUT > ... > <element_name>Brandon</element_name> > ... > > DESIRED OUTPUT > ... > <Tag>Brandon</Tag> > ... > > Does anyone know how I could achieve the desired output using only the > xml builder?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
LOL, much easy, i think so :D Happy coding. On Thu, Jul 22, 2010 at 8:30 AM, Ajit <ajitscorpio-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> try > > xml.instruct! > xml.data do > xml.tag "Brandon" > end > > this will give you: > > <data> > <tag>Brandon</tag> > </data> > > Cheers > > > > On Jul 21, 5:26 pm, Brandon <bemat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am using the XML builder and I am frustrated by the lack of being > > able to use variables to define the names of XML elements > > > > I want to be able to do this (in actionname.xml.builder) > > ... > > element_name = "Tag" > > xml.element_name("Brandon") > > ... > > > > ACTUAL OUTPUT > > ... > > <element_name>Brandon</element_name> > > ... > > > > DESIRED OUTPUT > > ... > > <Tag>Brandon</Tag> > > ... > > > > Does anyone know how I could achieve the desired output using only the > > xml builder? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Atte. ISC. Gerardo González Cruz -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Try using "send" to send the element name. So element_name = :tag xml.send(element_name) "Brandon" On Jul 21, 2:26 pm, Brandon <bemat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using the XML builder and I am frustrated by the lack of being > able to use variables to define the names of XML elements > > I want to be able to do this (in actionname.xml.builder) > ... > element_name = "Tag" > xml.element_name("Brandon") > ... > > ACTUAL OUTPUT > ... > <element_name>Brandon</element_name> > ... > > DESIRED OUTPUT > ... > <Tag>Brandon</Tag> > ... > > Does anyone know how I could achieve the desired output using only the > xml builder?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bensomers wrote:> Try using "send" to send the element name. So > > element_name = :tag > xml.send(element_name) "Brandon"thanx for your help. It was really helpful how can I add attribute. I want in this format <count date="20050412T00:00:00">214</count> how can I add attribute date. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
xml.count(:date=>service.date, service.code) ^ ^ ^ dot tag hash = attribute no hash = inner value On Wed, Sep 8, 2010 at 6:21 AM, Manish Nautiyal <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> bensomers wrote: > > Try using "send" to send the element name. So > > > > element_name = :tag > > xml.send(element_name) "Brandon" > > > thanx for your help. It was really helpful > > how can I add attribute. I want in this format > > <count date="20050412T00:00:00">214</count> > > how can I add attribute date. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.