简体   繁体   中英

Forcing Scala's XML library to render “singleton tag” (e.g., <br/>) as such

If I use the loadString method to load HTML containing a <br/> tag, Scala's XML lib wants to convert that to the longer, and seemingly less standard <br></br> (which unfortunately even seems to render differently than the plain-old <br/> in some browsers).

Ie, the following...

val xml = scala.xml.XML.loadString("<body>Hi<br/>there.</body>")
xml.toString()

...yields...

<body>Hi<br></br>there.</body>

Is there a way to force Scala's XML lib to render the tag as a "singleton"?

Not so!

scala> val xml = scala.xml.XML.loadString("<body>Hi<br/>there.</body>")
xml: scala.xml.Elem = <body>Hi<br/>there.</body>

scala> xml.toString()
res0: String = <body>Hi<br/>there.</body>

Of course, you are not using Scala 2.10.0, so you see what you are seeing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM