문제

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

도움이 되었습니까?

해결책

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.

다른 팁

The following will escape the ampersand:

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

Which, arguably, is what you really need.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top