Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: DOMDocument encoding in ouput from a VB6 application

From: "Jimmy" <aim@----------.--.-->
To: NULL
Date: 4/1/2005 6:41:00 AM
Got it sorted!

I am simply continuing with my XML file creation as described in my
initial post (i.e. I am creating a text file with the extension of
.xml)

I then need to run this file through ADODB.Stream setting certain
parameters, namley specify the charset to be UTF-8.

Just call the sub below passing in the full path of the file to be
SAVED (not ENCODED) as UTF-8.  I say SAVED because I am encoding the
contents of the file as UTF-8 (using a different sub) when I initially
create the XML output.  So basically, before I run the output file
through the sub below, I have an XML file that contains UTF-8 encoding,
but is saved as ANSI.  To correct this, I must then save the file as
UTF-8...

Private Sub saveAsUTF8(Path As String)
    Dim objUTF8 As ADODB.Stream
    Set objUTF8 = New ADODB.Stream

    objUTF8.Open
    objUTF8.LoadFromFile Path 'Loads a File
    objUTF8.Charset = "UTF-8" 'sets the stream encoding to UTF-8
    objUTF8.SaveToFile Path, adSaveCreateOverWrite 'Save File
    objUTF8.Close

    Set objUTF8 = Nothing
End Sub


'Sub for encoding the contents of a file into UTF-8:
Private Function Encode_UTF8(ByVal astr As String) As String
  Dim c As Long, n As Long
  Dim utftext As String
    utftext = ""
    For n = 1 To Len(astr)
        c = AscW(Mid(astr, n, 1))
        If c < 128 Then
            utftext = utftext + Mid(astr$, n, 1)
        ElseIf ((c > 127) And (c < 2048)) Then
            utftext = utftext + Chr(((c \ 64) Or 192))
            utftext = utftext + Chr(((c And 63) Or 128))
        Else
            utftext = utftext + Chr(((c \ 144) Or 234))
            utftext = utftext + Chr((((c \ 64) And 63) Or 128))
            utftext = utftext + Chr(((c And 63) Or 128))
        End If
    Next n

  Encode_UTF8 = utftext

End Function

Ciao 4 now...
Jimmy



transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent