Hi, How to embed ruby code in xml . here is my XML template : string = <<EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ozxmlscene> <ozml version="4.0"> <styleRun style="1091379" offset="0" length="7"/> <text>The End</text> <object value="84"/> <object value="104"/> <object value="101"/> <object value="32"/> <object value="69"/> <object value="110"/> <object value="100"/> <override>0</override> <aspectRatio>0.8999999762000001</aspectRatio> </ozml> EOF xml = string.gsub(''"'',"''") I need to use loop below <text> tag generating object values dynamically . How to embed this in xml ? end_title_name.each_byte do |title| "<object value=title/>" end thanks, sri.. -- Posted via http://www.ruby-forum.com/.
On Oct 20, 12:20 pm, "Srinath A." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > How to embed ruby code in xml . > > here is my XML template :Well as you''ve done things your template is just a string so the usual #{} interpolation will work. I''d encourage you to look at builder though. Fred> > string = <<EOF > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE ozxmlscene> > <ozml version="4.0"> > <styleRun style="1091379" offset="0" length="7"/> > <text>The End</text> > <object value="84"/> > <object value="104"/> > <object value="101"/> > <object value="32"/> > <object value="69"/> > <object value="110"/> > <object value="100"/> > <override>0</override> > <aspectRatio>0.8999999762000001</aspectRatio> > </ozml> > EOF > xml = string.gsub(''"'',"''") > > I need to use loop below <text> tag generating object values dynamically > . > How to embed this in xml ? > > end_title_name.each_byte do |title| > "<object value=title/>" > end > > thanks, > sri.. > -- > Posted viahttp://www.ruby-forum.com/.
hi, My file contains 5000 lines in which only 1000 lines are custom . So if use builder i should write by hand all these lines . thanks sri.. Frederick Cheung wrote:> On Oct 20, 12:20�pm, "Srinath A." <rails-mailing-l...@andreas-s.net> > wrote: >> Hi, >> >> How to embed ruby code in xml . >> >> here is my XML template : > > > Well as you''ve done things your template is just a string so the usual > #{} interpolation will work. I''d encourage you to look at builder > though. > > Fred-- Posted via http://www.ruby-forum.com/.
Srinath A. wrote:> hi, > > My file contains 5000 lines in which only 1000 lines are custom . > So if use builder i should write by hand all these lines .In your case, ERb might work better than Builder, or you could use a Builder partial for the custom stuff.> > > thanks > sri..Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
On Wed, Oct 21, 2009 at 5:13 AM, Marnen Laibow-Koser <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Srinath A. wrote: >> hi, >> >> My file contains 5000 lines in which only 1000 lines are custom . >> So if use builder i should write by hand all these lines . > > In your case, ERb might work better than Builder, or you could use a > Builder partial for the custom stuff.Here''s an example of using builder (in this case Nokogiri''s flavor) from within a .erb template as Marmen suggests. http://github.com/kete/kete/blob/master/app/views/search/rss.xml.erb Cheers, Walter
Walter McGinnis wrote:> On Wed, Oct 21, 2009 at 5:13 AM, Marnen Laibow-Koser > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Srinath A. wrote: >>> hi, >>> >>> My file contains 5000 lines in which only 1000 lines are custom . >>> So if use builder i should write by hand all these lines . >> >> In your case, ERb might work better than Builder, or you could use a >> Builder partial for the custom stuff. > > Here''s an example of using builder (in this case Nokogiri''s flavor) > from within a .erb template as Marmen suggests. > > http://github.com/kete/kete/blob/master/app/views/search/rss.xml.erbActually, I was suggesting not using Builder at all, in order that the 3000 static lines could just be part of an ERb file. The ERb could render the XML without needing Builder. But your approach is very interesting, and I''ll keep it in mind. I do have a question, though: what''s the advantage of embedding Builder in ERb as you did, rather than having the ERb file call a Builder partial?> > Cheers, > WalterBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
But i was looking to generate XML behind the scenes and it will write to a new file every time . If we use .erb this will try to render on screen ? right thanks sri. Marnen Laibow-Koser wrote:> Walter McGinnis wrote: >> On Wed, Oct 21, 2009 at 5:13 AM, Marnen Laibow-Koser >> <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >>> >>> Srinath A. wrote: >>>> hi, >>>> >>>> My file contains 5000 lines in which only 1000 lines are custom . >>>> So if use builder i should write by hand all these lines . >>> >>> In your case, ERb might work better than Builder, or you could use a >>> Builder partial for the custom stuff. >> >> Here''s an example of using builder (in this case Nokogiri''s flavor) >> from within a .erb template as Marmen suggests. >> >> http://github.com/kete/kete/blob/master/app/views/search/rss.xml.erb > > Actually, I was suggesting not using Builder at all, in order that the > 3000 static lines could just be part of an ERb file. The ERb could > render the XML without needing Builder. But your approach is very > interesting, and I''ll keep it in mind. > > I do have a question, though: what''s the advantage of embedding Builder > in ERb as you did, rather than having the ERb file call a Builder > partial? > >> >> Cheers, >> Walter > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org-- Posted via http://www.ruby-forum.com/.
Srinath A. wrote:> But i was looking to generate XML behind the scenes and it will write to > a new file every time .I know.> > If we use .erb this will try to render on screen ? rightWrong. The choice of ERb, Builder, Haml, or whatever makes no difference in this regard.> > > thanks > sri. > >Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
On Thu, Oct 22, 2009 at 3:49 PM, Marnen Laibow-Koser <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I do have a question, though: what''s the advantage of embedding Builder > in ERb as you did, rather than having the ERb file call a Builder > partial?Performance. Nokogiri''s builder is significantly faster than Builder from our testing at the time. Although you can swap parsing libs now in Rails, you still can''t use ".xml.nokogiri" yet. We used ERB in order to use Nokogiri, since the output is returned to ERB as a string. Cheers, Walter
Here''s some background including some loose benchmarking: http://kete.lighthouseapp.com/projects/14288/tickets/177-tags-list-rss-feed-increasingly-slower Cheers, Walter
Can we generate dynamic xml using REXML/XML Builder ? My requirement is to use a sample xml template which contains 5000 lines and each time when user clicks on GO, we will create a new xml file generating all 5000 lines and only approx 3000 lines will be dynamic like Eg: photo name , photo title, time, etc. So in my public folder i will have N no. of xml files for N no. of users (all files will generate 5000 lines) thanks sri.. Walter McGinnis wrote:> Here''s some background including some loose benchmarking: > > http://kete.lighthouseapp.com/projects/14288/tickets/177-tags-list-rss-feed-increasingly-slower > > Cheers, > Walter-- Posted via http://www.ruby-forum.com/.