![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - DOMDocument encoding in ouput from a VB6 application [Thread Next] Re: DOMDocument encoding in ouput from a VB6 applicationTo: 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
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
