Scales represents non Elem data as XmlItem, this includes Text, CData, PI (processing instructions) and Comment. They share the base trait XmlItem which provides one member:
val value : String
With PI also adding:
val target : String
val text = Text("A text value") val cdata = CData("Some cdata") val comment = Comment("A comment") val pi = PI("Target id","instruction value")
XmlItems, as with the rest of Scales - having separated data from structure, have no notion of ownership.
This implies they can be re-used both within and across documents. This follows with Elems and Trees themselves allowing whole sections of XML to be re-used.
There are a number of simple rules for XmlItems, driven by the spec:
Text, Comments and PI may contain character references and can be correctly serialized regardless of the encoding or Xml Version used.
CData is problematic to serialise due to:
The problems here should warn the user not use CData at all, as per ERH it does not add anything. It is only provided in Scales to allow documents to be passed through as is (e.g. content based routing).
Scales does its best to work around such issues including, forbidding CData splits, custom serializing (jre will write no end part to cdata) and verifying that the data can be written at all in the documents encoding.