|
|||
|
Hi,
I want to save xml files with textnodes in it containing special characters. So the xml has to be saved as unicode (which is also used by flash) How can I do this? example: var file_stream = new FileStream(getAppDir() + "\log.xml", "w"); file_stream.writeUnicodeString("<?xml version=\"1.0\" ?><f><n>b¨¦¨¤st</n></f>") file_stream.close(); This does not work: the extra nulChar at the end generates an error of you want to view the xml using IE (required). Any ideas? tnx |
|
|||
|
Code:
function toUTF8(string)
{
var i;
var stream = new StringStream;
for (i = 0; i < string.length; i++)
{
var code = string.charCodeAt(i);
if (code < (1 << 7))
{
stream.put(code);
}
else if (code < (1 << 11))
{
stream.put((code >> 6) | 0xC0);
stream.put((code & 0x3F) | 0x80);
}
else if (code < (1 << 16))
{
stream.put(0xE0 | ((code >> 12) & 0x0F));
stream.put(0x80 | ((code >> 6) & 0x3F));
stream.put(0x80 | (code & 0x3F));
}
else if (code < (1 << 21))
{
stream.put((code >> 18) | 0xe0);
stream.put(((code >> 12) & 0x3f) | 0x80);
stream.put(((code >> 6) & 0x3f) | 0x80);
stream.put((code & 0x3f) | 0x80);
}
}
return stream;
}
var file_stream = new FileStream("c:\\log.xml", "w");
file_stream.write(toUTF8('<?xml version="1.0" encoding="UTF-8"?><f><n>中国</n></f>'));
file_stream.close();
|
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|