Thanks Derek. Familiarity with the APIs is one of the tricks when moving to
a new language I guess.
This worked for me, but I have a follow-on issue.
Just as a background I am rendering search results which are provided as
XML. Here's my binding code:
result => bind("entry", chooseTemplate("listings", "listing", xhtml),
"title" -> <a href={result.url}>{Unparsed(result.title)}</a>,
"description" -> Unparsed(result.description),
"link" -> Text(result.url))
})
This fails to compile as the Unparsed in the description line is not a valid
parameter for the bind function. (I'm not sure why, it's just a fancy Node
like any other right?) The exact error is:
overloaded method value bind with alternatives
(String,net.liftweb.util.Box[(scala.xml.NodeSeq) =>
scala.xml.NodeSeq],net.liftweb.util.Box[(scala.xml.PrefixedAttribute) =>
scala.xml.MetaData],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)scala.xml.NodeSeq
<and>
(String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)scala.xml.NodeSeq
cannot be applied to
(java.lang.String,scala.xml.NodeSeq,net.liftweb.util.Helpers.TheBindParam,(String,
scala.xml.Unparsed),net.liftweb.util.Helpers.TheBindParam)
If I change that line to * "description" ->
Text(Unparsed(result.description))* it compiles, but the Text constructor
will re-escape so I'm back to square one.
If I change the line to "description" -> *
<span>{Unparsed(result.description)}</span>*, it compiles but I have an
unwanted span tag and worse ... if result.description is not well formed XML
my page will fail to render! Firefox complains of an XML Parsing Error. The
description field has an unmatched <br> tag (literally <br>) in the
middle of it to force it onto two lines.
So my first question is, how can I avoid the extra <span> tag?
Secondly, can I render (!X)HTML via Lift?
Thanks
Jeremy
2009/3/17 Derek Chen-Becker <[email protected]>
> Well, it may be that the XML output portion of Scala is escaping your
> ampersands a second time. For instance, check out this session in the
> interpreter:
>
> scala> val title = "Catsby & Twisp"
> title: java.lang.String = Catsby & Twisp
>
> scala> val escaped = <span>{title}</span>
> escaped: scala.xml.Elem = <span>Catsby &amp; Twisp</span>
>
> scala> val unescaped = <span>{ scala.xml.Unparsed(title) }</span>
> unescaped: scala.xml.Elem = <span>Catsby & Twisp</span>
>
>
> Note that if you embed a String within XML elements, Scala will
> automatically escape any ampersands unless you wrap the String in a
> scala.xml.Unparsed instance. The second test there will render in the
> browser like "Catsby & Twisp", because the ampersand was escaped. I know
> you're asking about the Utility object, but I think that would be fixing the
> symptom rather than the cause.
>
> Derek
>
>
> On Mon, Mar 16, 2009 at 6:13 AM, Jeremy Mawson <
> [email protected]> wrote:
>
>> Hi,
>>
>> I've been mucking around with lift and having a great time. I have cooked
>> up a page that retrieves XML from a datasource and renders it. However some
>> of the text elements I extract are HTML encoded. When rendered in the
>> browser it looks like HTML code, rather than rendered HTML.
>>
>> I looked for a scala utility to unescape this, found
>> scala.xml.Utility.unescape, but could not get it working.
>>
>> Here's how I've tried to use it.
>>
>> val title = Utility.unescape(result \ "title" text, new
>> StringBuilder)
>>
>> Unfortunately this always gives me a value of null, even though
>> result.\("title").text is something like - "Tsvangirai&#39;s wife killed
>> in<b>car</b>crash - ABC News"
>>
>> What could I be doing wrong? I realise this is probably a plain old scala
>> question, but I hope someone here can help me anyway.
>>
>> Thanks
>> Jeremy
>>
>>
>>
>
> >
>
--
Jeremy Mawson
Senior Developer | Online Directories
Sensis Pty Ltd
222 Lonsdale St
Melbourne 3000
E: [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---