Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-08-2005, 11:32 AM
Member
 
Join Date: Apr 2005
Location: Antwerp, Belgium
Posts: 40
Default save XML in unicode format

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
Reply With Quote
  #2 (permalink)  
Old 06-09-2005, 03:08 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:save XML in unicode format

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();
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:27 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.