Question

In order to generate valid XML closing tags must be provided in order to pass the type checker (yes, you can add a single element with a trailing slash like <foo /> but generated xml node is <foo ></foo>)

For XHMTL this can cause problems, particularly with standalone tags like br, img, and in my current case, the much needed <wbr> tag.

Is there a way to omit the trailing tag, or is this not possible?

I'm building up XHTML using a NodeBuffer if that helps

Can't find any thread newer than 2011 that points remotely in this direction so I suspect not.

Was it helpful?

Solution

Strictly speaking, XHTML must be valid XML, so this shouldn't be an issue.

Stand-alone tags are, as you noted, indicated with the trailing slash (<br/>).

How that tag is specified (in code) or printed, <br/> or <br></br>, is simply a choice - it's still a single node without child elements.

OTHER TIPS

You can mark standalone XML tags like so:

<br />

instead of

<br>

This is valid in Scala, so you can write

val x = <br />

instead of

val x = <br><br/>

Note that the following will cause a compile-time error:

val x = <br>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top