How to create xhtml query strings with Scala?
-
22-09-2019 - |
Question
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().
Solution
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&key2=val2">link</a>
See Using Ampersands in Attribute Values (and Elsewhere) in the XHTML 1.0
reference.
OTHER TIPS
The following will escape the ampersand:
val node = <a href={"link?key=val&key2=val2"}>link</a>
Which, arguably, is what you really need.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow