REXML

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

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:

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,

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:

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,

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:

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: