有人能告诉我是否可以从Visual Basic 6中没有架构的xml字符串加载记录集?
例如:
Dim strXml as strng
strXml = “<root><rec><fld>data</fld></rec></root>”
Dim oStream As adodb.Stream
Set oStream = New adodb.Stream
oStream.Open
oStream.WriteText strXml
oStream.Position = 0
Dim objRs As adodb.Recordset
Set objRs = New adodb.Recordset
objRs.Open oStream
oStream.Close
Set oStream = Nothing
‘Loop objRs data
Set objRs nothing
提前谢谢。
答案 0 :(得分:1)
是的,这是可能的,并且您的代码与Microsoft支持的此代码非常相似。
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
完整的微软帖子:https://support.microsoft.com/en-us/kb/263247
OP正确地指出,这限制为,&#34; ADO记录集可以接受的格式&#34;,并且该格式中嵌入了架构。