I need to create a XML document with ISO-8859-1 encoding.  This option is not available in XML Ports so what can you do?

I wrote the following function to read an UTF-8 encoded file and convert it to ISO-8859-1.
[code htmlscript=”false”]PROCEDURE UFT8File_To_ISO88591File@1200050006(UFT8_FileName@1200050000 : Text[1024];ISO88591_FileName@1200050001 : Text[1024]);
VAR
UFT8Stream@1200050008 : Automation "{2A75196C-D9EB-4129-B803-931327F72D5C} 2.8:{00000566-0000-0010-8000-00AA006D2EA4}:’Microsoft ActiveX Data Objects 2.8 Library’.Stream";
ISOStream@1200050007 : Automation "{2A75196C-D9EB-4129-B803-931327F72D5C} 2.8:{00000566-0000-0010-8000-00AA006D2EA4}:’Microsoft ActiveX Data Objects 2.8 Library’.Stream";
String@1200050009 : Text[1024];
adReadAll@1200050002 : Integer;
adSaveCreateOverWrite@1200050003 : Integer;
adTypeBinary@1200050004 : Integer;
adTypeText@1200050005 : Integer;
adWriteChar@1200050006 : Integer;
BEGIN
adReadAll := -1;
adSaveCreateOverWrite := 2;
adTypeBinary := 1;
adTypeText := 2;
adWriteChar := 0;

CREATE(UFT8Stream);
CREATE(ISOStream);
UFT8Stream.Open;
UFT8Stream.Type := adTypeBinary;
UFT8Stream.LoadFromFile(UFT8_FileName);
UFT8Stream.Type := adTypeText;
UFT8Stream.Charset := ‘UTF-8’;

ISOStream.Open;
ISOStream.Type := adTypeText;
ISOStream.Charset := ‘iso-8859-1′;
WHILE NOT UFT8Stream.EOS DO BEGIN
String := UFT8Stream.ReadText(MAXSTRLEN(String));
ISOStream.WriteText(String,adWriteChar);
END;
ISOStream.SaveToFile(ISO88591_FileName,adSaveCreateOverWrite);
ISOStream.Close;
CLEAR(ISOStream);
UFT8Stream.Close;
CLEAR(UFT8Stream);
END;[/code]
Then I stream the BLOB that holds the UTF-8 encoded XML to a file and convert it.
[code htmlscript=”false”]IF ISCLEAR(SystemShell) THEN
CREATE(SystemShell);

Log."Outgoing Message".CREATEINSTREAM(InStr);
UFT8_FileName := ThreeTierMgt.ServerTempFileName(”,’XML’);
PaySlipFile.CREATE(UFT8_FileName);
PaySlipFile.CREATEOUTSTREAM(OutStr);
COPYSTREAM(OutStr,InStr);
PaySlipFile.CLOSE;
IF ISSERVICETIER THEN BEGIN
ISO_FileName := ThreeTierMgt.ServerTempFileName(”,’XML’);
Helper.UFT8File_To_ISO88591File(UFT8_FileName,ISO_FileName);
PaySlipFile.OPEN(ISO_FileName);
PaySlipFile.CREATEINSTREAM(InStr);
DOWNLOADFROMSTREAM(InStr,Text006,”,Text007,ToFile);
SystemShell.DeleteFile(ISO_FileName);
END ELSE BEGIN
ISO_FileName := ToFile;
Helper.UFT8File_To_ISO88591File(UFT8_FileName,ISO_FileName);
END;
SystemShell.DeleteFile(UFT8_FileName);[/code]
Manually you will need to replace the first line in the XML Document from ‘<?xml version=”1.0″ encoding=”UTF-8″ ?>’ to ‘<?xml version=”1.0″ encoding=”ISO-8859-1″?>’

 

Leave a Reply

%d bloggers like this: