I`ve come across a problem when serializing special characters like TAB, linefeed and carriage return as an attribute value.
According to this http://www.w3.org/TR/1999/WD-xml-c14n-19991109.html#charescaping, these should be encoded as &\#x9;
, &\#xA;
, and &\#xD;
respectively. But calling in chrome:
var root = new DOMParser().parseFromString('<root></root>', 'text/xml').documentElement;
root.setAttribute('a', 'first\nsecond');
var serialized = new XMLSerializer().serializeToString(root);
Gives a string < root a="first\nsecond"/>
with the linefeed not escaped.
When loading that again:
var loaded = new DOMParser().parseFromString(serialized, 'text/xml').documentElement;
loaded.getAttribute('a');
returns "first second" and the linefeed was lost to just a space. Has anyone faced this issue before? Any help would be appreciated.
Thanks,
Viktor