Is this valid XML data (the value of the messageContent in particular)?
I am getting it from an API.
I then get an error when I pass this XML down to a Postgres function for saving to the Postgres DB.
<rows>
<row messageDateUTC="2020-06-01T21:20:37.120"
texterAddress="" texterStreet="" messageContent="Hey beautiful it's Scott!��" />
</rows>
I wonder if it's an API issue, or a problem with the client-side module which generates the XML, or maybe Postgres has an issue and is not able to handle these characters.
Error here:
Caused by: org.postgresql.util.PSQLException: ERROR: invalid XML content
Detail: line 5: xmlParseCharRef: invalid xmlChar value 55357
ddress="" texterStreet="" messageContent="Hey beautiful it's Scott!�
^
line 5: xmlParseCharRef: invalid xmlChar value 56842
" texterStreet="" messageContent="Hey beautiful it's Scott!��
^
line 23: chunk is not well balanced
tl;dr No, they are not valid, whatever did the encoding is either buggy or got told wrong encoding information about the input.
55357 and 56842 are 0xD83D and 0xDE0A in hex respectively.
In Unicode they are in ranges called "High Surrogate" and "Low Surrogate" respectively.
That means that they are not proper Unicode codepoints, but rather used in UTF-16 to construct a single Unicode value that doesn't fit into 16 bit (i.e. the Basic Multilingual Plane).
These two specific values decode to U+1F60A SMILING FACE WITH SMILING EYES. The correct decimal HTML entity for that would be 😊.
The most likely reason for this is that some transformation that either doesn't know about UTF-16 or thought this text is not UTF-16 did the encoding (but should have detected that those values are invalid and reported an error even in that case).