I am trying to generate some XML on-the-fly in Scala.
I want to use a numeric character reference inside the XML and write out the resultant XML to an output stream.
Example:
val myXml = <body>Hello World</body>
val writer = new java.io.FileWriter("test")
scala.xml.XML.write(writer, myXml, "utf-8", false, null)
8198 is unicode for a tiny space character.
After the above snippet is run, the contents of the file "test" are
<body>Hello World</body>
What I am expecting instead is,
<body>Hello World</body>
Edit: Learnt how to escape XML in SO
From stackoverflow
HRJ
-
You need to write:
import scala.xml.EntityRef ... val myXml = <body>Hello{EntityRef("#8198")}World</body>HRJ : Thanks. This works, with a minor change: EntityRef("#8198")Walter Chang : @HRJ Thanks, corrected.From Walter Chang
0 comments:
Post a Comment