Home Forums General XMetaL Discussion xml property of ActiveDocument object and UTF-8 Reply To: xml property of ActiveDocument object and UTF-8

Derek Read

Reply to: xml property of ActiveDocument object and UTF-8

Yeah, so FSO is definitely the problem here.

One way around this issue is to use ADODB.Stream, which does support UTF-8 but what you need to get that working is pretty convoluted in my opinion. If you Google for “FSO createfile UTF-8” many of the hits will point you to ADODB.Stream or other non-FSO solutions.

We have some undocumented code that you might try that may be easier to use than ADODB.Stream. However, because it is undocumented you'd need to figure out how we use it by looking at our scripts. It would essentially go something like this:

var cwUtil = new ActiveXObject("CWUtil.StringUtil");
      if (!cwUtil) return false;
      cwUtil.StringToUTF8File(xmlStr, tempFileName);

The cwUtil is a DLL that we install and register so it is available to all XMetaL Author installations (both Essential and Enterprise). However, a JS file that demonstrates it is only included as part of the DITA solution that comes with Enterprise here: DITAXACssharedditajsdita_utils.js

Here is a similar example that might actually be easier to understand. Make particular note of the (somewhat ironic) warnings in the comments, and sorry — JScript again as most of our internals are standardized on that script language (this is written as a JScript prototype as the DLL is somewhat limited in functionality w.r.t. file cleanup, etc):

[code]XMAULocalFileSystemService.prototype.SaveXMLToUTF8File = function(xmlStr, filePath)
{
      // PROD00032235: XMXML would help out here since Xerces wants to
      // resolveExternals, MSXML doesn't like the DITA DTDs, FSO's unicode-mode
      // write UTF16 plus a BOM (which Documentum doesn't like)….so, we do
      // the following:
      //
      //  1. Create temp filename that uses only ascii chars
      //  2. Use CWUtil which can write temp using UTF8 but StringToUTF8File()
      //      only works if file name is ascii
      //  3. Use FSO to copy to temp file to filename with unicode chars
      //  4. Delete temp file
     
      if (!xmlStr || !filePath) return false;
      var folderName = this.GetParentFolderName(filePath);
      var tempFileName = Application.UniqueFileName(folderName, “__”);
     
      var cwUtil = new ActiveXObject(“CWUtil.StringUtil”);
      if (!cwUtil) return false;
      cwUtil.StringToUTF8File(xmlStr, tempFileName);
     
      this.CopyFile(tempFileName, filePath, true);
      this.DeleteFile(tempFileName, true);
      return true;                 
}[/code]

Reply

Products
Downloads
Support