What I would like to do is dump an XML String into RecordSet. The problem I am having is that the code seems to work fine if I saved the XML String first to a file and then read from the file which I think is redundant. However, when I want to read from string, I get the error
RecordSet cannot be created. Source XML is incomplete or invalid. 80004005
My XML String is in the form
<portfolio>
<stock>
<shares>100</shares>
<symbol>MSFT</symbol>
<price>$70.00</price>
<info>
<companyname>Microsoft Corporation</companyname>
<website>http://www.microsoft.com</website>
</info>
</stock>
<stock>
<shares>100</shares>
<symbol>AAPL</symbol>
<price>$107.00</price>
<info>
<companyname>Apple Computer, Inc.</companyname>
<website>http://www.apple.com</website>
</info>
</stock>
<stock>
<shares>100</shares>
<symbol>DELL</symbol>
<price>$50.00</price>
<info>
<companyname>Dell Corporation</companyname>
<website>http://www.dell.com</website>
</info>
</stock>
<stock>
<shares>100</shares>
<symbol>INTC</symbol>
<price>$115.00</price>
<info>
<companyname>Intel Corporation</companyname>
<website>http://www.intel.com</website>
</info>
</stock>
</portfolio>
And the code I am using to convert the XML String(That I am having the problem with) is
Public Function RecordsetFromXMLString(sXML As String) As Recordset
Dim oStream As ADODB.Stream
Set oStream = New ADODB.Stream
oStream.Open
oStream.WriteText sXML 'Give the XML string to the ADO Stream
oStream.Position = 0 'Set the stream position to the start
Dim oRecordset As ADODB.Recordset
Set oRecordset = New ADODB.Recordset
oRecordset.Open oStream 'Open a recordset from the stream
oStream.Close
Set oStream = Nothing
Set RecordsetFromXMLString = oRecordset 'Return the recordset
Set oRecordset = Nothing
End Function
Please, your help will be greatly appreciated.
http://msdn.microsoft.com/en-us/library/ms810621
http://support.microsoft.com/kb/263247
I already tried using this below
Public Function RecordsetFromXMLDocument(XMLDOMDocument)
Dim oRecordset
Set oRecordset = CreateObject("ADODB.Recordset.6.0")
oRecordset.Open XMLDOMDocument 'pass the DOM Document instance as the Source argument
Set RecordsetFromXMLDocument = oRecordset 'return the recordset
Set oRecordset = Nothing
End Function
But still ran into the same issue.