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

点点圈 提交于 2020-01-16 00:57:28

问题


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

I.e., 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"?


回答1:


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.



来源:https://stackoverflow.com/questions/14948284/forcing-scalas-xml-library-to-render-singleton-tag-e-g-br-as-such

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!