Clear Filters
Clear Filters

utf-16 encoding in writestruct /readstruct or other xml2struct functions

37 views (last 30 days)
I have a large xml file that is used to store information and settings for variables used in another program. It holds the variable name, units, description, display name. That kind of thing.
Due to some weird error with another program, someone tried to import this variable set and instead of overwriting the existing variables on that system it merged them. So I now have this xml file with over 400 duplicate entries and over 2000 entries in total.
I've already sorted a way of finding and removing these but the problem has come with encoding. The original xml file is in UTF-16 and it needs this presumably because of the japanese characters that are used for the variable descriptions etc.
Presumably then I need to have matlab not convert to utf-8 on reading and also save as utf-16 on saving. Is this possible?
I've been using community functions xml2struct and struct2xml but I see there are also native matlab options of readstruct and writestruct. But its not clear if they are capable of doing UTF-16 or whether its a selectable option?
  3 Comments
Alex Mason
Alex Mason on 22 Aug 2024 at 7:29
@Walter Roberson Do I use this unicode conversion before I am exporting using struct2xml? or doing it once the new xml is made?
Walter Roberson
Walter Roberson on 22 Aug 2024 at 21:16
You would struct2xml() returning the generated xml, which would be generated with utf-8. You would "fix up" the header that says encoding utf-8 to say utf-16 instead. You would uint8() that to convert from characters to bytes, and you would native2unicode() the bytes to convert into unicode code points. You would then unicode2native() that char stream asking for UTF-16, generating a byte stream. You would fwrite() the byte stream.

Sign in to comment.

Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!