Forum: Ruby on Rails is there simpler way to export html within xml

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.
Todd F. (Guest)
on 2009-05-07 16:32
Hi,

we're exporting a lot of html code within xml, our current method works
but it's very messy - far from perfect, is there a better way to do
this.

an example of our controller code is

html = html + "<img src="/icon/icon_email.gif"
onclick="javascript:document.getElementById('detail').style.display='none';
document.getElementById('mailform').style.display='inline';
"/>\n"

as you can see we're using the < etc to generate the html required,
so the end result is something like

  <marker html="<img src="/icon/icon_email.gif"
onclick="javascript:document.getElementById('detail').style.display='none';
document.getElementById('mailform').style.display='inline'; "/>...

so within that xml tag you can see a html= option, and within that
option lives all our html.

can anyone suggest a cleaner better way to do this? it would really be
appreciated.

thanks
Colin L. (Guest)
on 2009-05-07 17:12
(Received via mailing list)
Is it too naive to suggest using the view (or a pseudo view) to generate
the
html using erb?  After all that is what erb is for.
Colin

2009/5/7 Todd F. <removed_email_address@domain.invalid>
Todd F. (Guest)
on 2009-05-07 20:26
how would that work?
Todd F. (Guest)
on 2009-05-07 20:28
Todd F. wrote:
> how would that work?

we need the html in xml (html wrapped inside the xml) for another
application read and then render that html.
Colin L. (Guest)
on 2009-05-08 00:35
(Received via mailing list)
I am not sure exactly what you would do, I am also not sure exactly what
you
are doing with the xml.  It just seems that an erb view is the ideal
tool
for generating html to be sent to the client.  Is there a lot of xml or
is
it just a wrapper round the html?  If only a wrapper then you could
generate
that 'by hand' so to speak in the erb file also, or in the layout file.

Can anyone else help? I do not really know what I am talking about here.

Colin

2009/5/7 Todd F. <removed_email_address@domain.invalid>
Hassan S. (Guest)
on 2009-05-08 00:52
(Received via mailing list)
On Thu, May 7, 2009 at 9:28 AM, Todd F.
<removed_email_address@domain.invalid> wrote:

> we need the html in xml (html wrapped inside the xml) for another
> application read and then render that html.

Does the html need to be an attribute? Or can it just be within an
xml envelope?  IOW, do you control the consuming end of this?

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Todd F. (Guest)
on 2009-05-08 06:34
sorry more info on what it's used for would help, the xml is being read
by google maps api so we can load html code inside the popup bubble.

so yeah we dont really control the consuming end :(
Marnen L. (Guest)
on 2009-05-08 06:39
Todd F. wrote:
> sorry more info on what it's used for would help, the xml is being read
> by google maps api so we can load html code inside the popup bubble.
>
> so yeah we dont really control the consuming end :(

It seems to me, then, that you have two good options.  Either use ERb
and/or Builder to put the HTML in the XML DOM, or (if the HTML has to be
a string) use a CDATA section.  Don't make your life harder with all
those &entities;.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
removed_email_address@domain.invalid
Todd F. (Guest)
on 2009-05-08 06:41
thanks Marnen and everyone, do you know of any examples or something i
can have a look at to get my head around it?
Marnen L. (Guest)
on 2009-05-08 06:50
Todd F. wrote:
> thanks Marnen and everyone, do you know of any examples or something i
> can have a look at to get my head around it?

What's to get your head around?  Just pretend your XML file is an HTML
page, and proceed accordingly with your favorite template language (ERb,
Builder, Haml, Markaby, whatever).  There's no new concept involved.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
removed_email_address@domain.invalid
Hugh T. (Guest)
on 2009-05-08 20:41
(Received via mailing list)
Way to be appreciative of someone trying to help you.  Good luck with
that.

On May 7, 9:50 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
Hugh T. (Guest)
on 2009-05-08 20:42
(Received via mailing list)
My bad MLK.
Todd F. (Guest)
on 2009-05-11 06:57
what are you talking about hugh?! :|

thanks Marnen, we'll try to render xml using an erb this week and let
everyone know if we can do it and how :P
This topic is locked and can not be replied to.