Rexml

Hi,

How to embed ruby code in xml .

here is my XML template :

string = <<EOF

<?xml version="1.0" encoding="UTF-8"?> The End 0 0.8999999762000001 EOF xml = string.gsub('"',"'")

I need to use loop below tag generating object values dynamically
.
How to embed this in xml ?

 end_title_name.each_byte do |title|
    "<object value=title/>"
 end

thanks,
sri…

On Oct 20, 12:20 pm, “Srinath A.” [email protected]
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

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 C. wrote:

On Oct 20, 12:20�pm, “Srinath A.” [email protected]
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

On Wed, Oct 21, 2009 at 5:13 AM, Marnen Laibow-Koser
[email protected] 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
[email protected] 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
[email protected]

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
[email protected]

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
[email protected] 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
[email protected]

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 ? right

Wrong. The choice of ERb, Builder, Haml, or whatever makes no
difference in this regard.

thanks
sri.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Here’s some background including some loose benchmarking:

http://kete.lighthouseapp.com/projects/14288/tickets/177-tags-list-rss-feed-increasingly-slower

Cheers,
Walter

On Thu, Oct 22, 2009 at 3:49 PM, Marnen Laibow-Koser
[email protected] 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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs