perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
home » focus » msxml » ask a question » past questions & answers Friday, 12 October 2007
 
NEWS
MSXML 4.0 SP2 now available!

 
MSXML
Basics
DOM
SAX
XPath
XSLT
Schemas
SOM
HTTP Access
.NET
Data Islands
Ask a Question
   Past Q&As
C++ Samples
DLL/Version Info
Reference Guide
Books
KB Articles
   HOW TO
   SAMPLE
   INFO
   BUG/PRB
   FIX
   Misc.
MSXML Tips
   August 2002
   September 2002
MSXML Tools

Microsoft XML Core Services


Go back to list of previously asked questions and answers

Question: I am using MSXML 4.0 DOM to save the loaded XML document into ADO Stream, but it is not working and I am getting an error "Object doesn't support this property or method" on the .save line. Here is my code:

Dim xDoc As Msxml2.DOMDocument40
Dim oStream As ADODB.Stream 'ADO 2.6
. . .
. . .
    Set oStream = New ADODB.Stream
    oStream.open
    xmlDoc.save (oStream)
Asked By: Kurt
Viewed: 2648
Answer: 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.


Go back to list of previously asked questions and answers
  Contact Us |  | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy