First remove the parentheses around the oStream object when calling .save and then remember to set the stream Charset to "iso-8859-1". Here is the sample VB 6.0 code that you can try with MSXML 4.0 and ADO 2.6. Remember to set reference to both (MSXML 4.0 and ADO 2.6) type libraries.
Dim ObjXMLDoc As New MSXML2.DOMDocument40
Dim ObjStream As New ADODB.Stream
ObjXMLDoc.async = False
ObjXMLDoc.validateOnParse = False
ObjXMLDoc.Load "c:\books.xml"
ObjStream.Open
ObjStream.Charset = "iso-8859-1"
ObjXMLDoc.save ObjStream
ObjStream.Position = 0
While Not ObjStream.EOS
Debug.Print ObjStream.ReadText
Wend
ObjStream.Close
See the following KB Article for details:
PRB: Error Occurs When You Open an ADO Recordset on an XML Stream (Q259555): When a recordset is saved to a file in an XML format, the data written to the file by the Microsoft Persistence Provider is in the UTF-8 encoding charset.
However, the default character set of an ADO Stream object is Unicode ( UTF-16 ) with byte order mark 0xFFFE . So, when the UTF-8 format file is loaded into the ADO stream, the internal buffer of the ADO stream contains the UTF-8 data but the data is prepended with 0xFFFE Unicode byte order marks. This causes the XML parser to fail, and the XML parser does not process the data when the ADO stream is used to open a recordset.
If the recordset is saved to a Stream in XML format, the data written to the stream is in Unicode encoding charset, that is, UTF-16 , which is the same as the default encoding used for an ADO stream.
|