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="…
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.
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.
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;.
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.