I have a servlet coded in Scala. I have some code like this in there:
def message = <HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>{value}</BODY></HTML>
def value = "Hello <BR/> World"
The corresponding HTML code generated for value is
Hello <BR/> World
How do I get it to generate the HTML code (shown below)?
Hello <BR/> World
Thanks in advance
If you don’t mind changing the type of
valuetoxml.Elem, you can doAddition
In my opinion, you should type as much XML inline as possible. Only then will you have compile time validation of the input. All other solutions either give you a runtime exception at some point (say, you forgot some
/) or might even break your XML layout.However, if you really want to have an easy transform, you could do this:
and then (for some reason, it still shows the
<xml:group>part; you could get rid of it withxml.NodeSeq.fromSeq(value.assumeXML.child)or similar)or even (well, you would not need the implicit here,
Unparsed(value)would do)The
assumeXMLmethod will fail with at runtime, if you provide invalid XML;toUnparsedXMLwill accept all input, even data that is potentially dangerous.