ballerina-spec
ballerina-spec copied to clipboard
Equality of XML values with escape characters.
In the following program, all xml values a
,b
, and c
are equal. But we found a scenario, where users want to preserve the original literal with the value. Right now this is not possible with jBallerina, since we take the canonical form at runtime. Created this issue to see, is there anything we can do from the language side.
import ballerina/io;
public function main() {
xml a = xml `<data><a title="< >">< ></a><b><![CDATA[ < > ]]></b></data>`;
xml b = xml `<data><a title="< >">< ></a><b> < > </b></data>`;
xml c = xml `<data><a title="< >">< ></a><b> < > </b></data>`;
io:println(a == b); // true
io:println(a == c); // true
io:println(a.toString()); // <data><a title="< >">< ></a><b> < > </b></data>
io:println(b.toString()); // <data><a title="< >">< ></a><b> < > </b></data>
io:println(c.toString()); // <data><a title="< >">< ></a><b> < > </b></data>
}
Preserving every detail of the original literal in the parsed representation would be hugely complicated (e.g. spaces inside tags, single vs double quotes around attribute literals, numeric escapes - it goes on and on).
You really need to dig into why they (think they) want to preserve the literal.