ballerina-spec icon indicating copy to clipboard operation
ballerina-spec copied to clipboard

Equality of XML values with escape characters.

Open hasithaa opened this issue 2 years ago • 1 comments

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="&lt; &gt;">&lt; &gt;</a><b><![CDATA[ &lt; &gt; ]]></b></data>`;
    xml b = xml `<data><a title="&lt; >">&lt; ></a><b> &lt; &gt; </b></data>`;
    xml c = xml `<data><a title="&lt; >">&lt; ></a><b> &lt; > </b></data>`;
    io:println(a == b); // true
    io:println(a == c); // true
    io:println(a.toString()); // <data><a title="&lt; >">&lt; ></a><b> &lt; > </b></data>
    io:println(b.toString()); // <data><a title="&lt; >">&lt; ></a><b> &lt; > </b></data>
    io:println(c.toString()); // <data><a title="&lt; >">&lt; ></a><b> &lt; > </b></data>
}

hasithaa avatar Feb 10 '23 08:02 hasithaa

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.

jclark avatar Feb 11 '23 01:02 jclark