4

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().

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

The following will escape the ampersand:

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

Which, arguably, is what you really need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.