views:

137

answers:

2

How do I create an x(ht)ml-Node containing a href-attribute including a query string without the &s being escaped automatically or runtime error?

val text = Text("?key=val&key2=val2")

will be escaped and

val node = <a href="link?key=val&key2=val2">link</a>

throws (in Scala 2.7.5):

java.lang.AssertionError

The node will be used with the Lift bind() helper method, preferably with AttrBindParam().

+4  A: 

try:

val text = scala.xml.Unparsed("link?key=val&key2=val2")
val node = <a href={text}>link</a>

But may be you really mean:

val node = <a href="link?key=val&amp;key2=val2">link</a>

See Using Ampersands in Attribute Values (and Elsewhere) in the XHTML 1.0 reference.

huynhjl
+1  A: 

The following will escape the ampersand:

val node = <a href={"link?key=val&key2=val2"}>link</a>

Which, arguably, is what you really need.

Daniel