Forum: Ruby on Rails XML Element attributes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ff920da319305b65c9ead68dfeebded4?d=identicon&s=25 maestro777 (Guest)
on 2007-07-25 00:03
(Received via mailing list)
Hi.

I'm trying to create an XML file of the following schema:

<data>
  <event start = "July 12 2007 " end="July 14 2007 ">
     Some description text here
   </event>
  <event start = "July 20 2007 " end="July 30 2007 ">
     Some description text here
   </event>
</data>



And I only managed to accomplish the following schema:

<data>
    <event>
      <start>July 12 2007</start>
      <end>July 14 2007</end>
      <p> Some description text here </p>
     </event>
      <start>July 20 2007</start>
      <end>July 30 2007</end>
      <p> Some description text here </p>
</data>

using the following codes:

xml.instruct! :xml, :version=>"1.0"
xml.data{
  for vac in @vacations
    xml.event do
    xml.start(vac.start_date.strftime"%B %d %Y" )
    xml.end (vac.end_date.strftime"%B %d %Y" )
    xml.p(vac.description)
    end
  end
}

Can someone help point out how I may accomplish that? Having the
element in the format of
<event start = "...." end="..." >Some text here </event>

Thank you in advance for your help.
1f2eadfb41362800ebc2cf211b91d0f7?d=identicon&s=25 javier ramirez (Guest)
on 2007-07-25 00:29
(Received via mailing list)
Hi,
> I'm trying to create an XML file of the following schema:
> <data>
>
> <event start = "July 12 2007 " end="July 14 2007 ">
>      Some description text here
>

you can pass the text of the tag as the first parameter and any
attributes as a hash.

xml.event 'Some description text', :start=>'July 12 2007', :end=>'July
14 2007'

regards,

javier ramirez
Ff920da319305b65c9ead68dfeebded4?d=identicon&s=25 maestro777 (Guest)
on 2007-07-25 00:56
(Received via mailing list)
It works great for me.
Thank you SO much Javier for your help.
This topic is locked and can not be replied to.