TXB: txscene files, ASCII and UTF-8
by Alex Loret de Mola · in Torque X 2D · 07/16/2010 (2:34 am) · 3 replies
So after a thoroughly frustrating venture with txscene files suddenly not loading in our project, I've found that though txscene files are labeled in their underlying XML structure as being UTF-8 encoded, they appear to actually be 7-bit ASCII encoded: and subsequently saving them to actually be UTF-8 results in the txscene files not being able to be loaded at all in TXB. It fails silently, without an error in the log in TXB.
Was this a known issue? If not, I would like to file it as a bug. I'm using TXB Version 2.0.0.0 according to the "About" dialog in TXB (which seems odd, because it's Torque X 3.1.4). I can provide example files if it will help.
Was this a known issue? If not, I would like to file it as a bug. I'm using TXB Version 2.0.0.0 according to the "About" dialog in TXB (which seems odd, because it's Torque X 3.1.4). I can provide example files if it will help.
About the author
Hi! I'm Alex Loret de Mola, AKA Vendal Thornheart, of Medaverse Studios. We're trying out tech for our new game, and Torque X's rapid prototyping has caught our eye! I finally got off my butt and got a license! =)
#2
In which case it is writing out a 'utf-8 id' at the beginning of the file - this is a few bytes you can see if you open in a binary file editor. Although it's technically okay TXB doesn't like it.
You can disable utf-8 id emmission like so:
The above assumes that xml is an instance of XmlDocument that you want to save.
07/16/2010 (11:16 am)
Sounds like you are saving the XML using c# XmlDocument?In which case it is writing out a 'utf-8 id' at the beginning of the file - this is a few bytes you can see if you open in a binary file editor. Although it's technically okay TXB doesn't like it.
You can disable utf-8 id emmission like so:
XmlTextWriter writer = new XmlTextWriter(fileName, new UTF8Encoding(false)); // note: turn of utf-8 id emmission as tx editor doesn't like it writer.Formatting = Formatting.Indented; writer.Indentation = 4; xml.Save(writer); writer.Close();
The above assumes that xml is an instance of XmlDocument that you want to save.
#3
Text diff utilities must ignore those IDs when doing DIFFs then, which would explain why the files looked identical otherwise. Interesting!
I solved the problem temporarily by forcing the XmlTextWriter to use ASCII formatting, but I'll switch it over to the solution you proposed here: if Torque X Builder can read UTF-8, I'd rather use that if at all possible. =)
Thank you again Duncan, you rock! =)
07/17/2010 (2:37 am)
Ah, indeed that's what was happening! Interesting... so the Torque X Builder can read UTF-8, but not the opening bytes that it writes. Very strange! I assumed that the mismatch was because of the ASCII encoding... I go into it in the blog link, but my text editor interpreted it as ANSI and I (admittedly) leapt to the conclusion that they may have mistaken ANSI for ASCII (which is a pretty common occurrence from what I can tell).Text diff utilities must ignore those IDs when doing DIFFs then, which would explain why the files looked identical otherwise. Interesting!
I solved the problem temporarily by forcing the XmlTextWriter to use ASCII formatting, but I'll switch it over to the solution you proposed here: if Torque X Builder can read UTF-8, I'd rather use that if at all possible. =)
Thank you again Duncan, you rock! =)
Torque Owner Alex Loret de Mola
vthornheart.railsplayground.net/blog/?p=534