How to convert XML->recordset

admin

Administrator
Staff member
Hi,Sorry to bother you, but I don't know the XML ->recordset method.I am writing a COM to provide the following fuction:After load XMLObject(String) in,Search the XML string by keyword and output the filtered XMLObject(String);or Sort the XML string by the keyword and output the sorted XMLObject(String);So I use the stream to store the XML string and want to pass it to recordset(andwant to use recordset's property--sort and filter to put my function intouse), the following is the code:Public Function xmlSearchBy(strXML As String, strKeywordForSearch As String)As String' Search based on the keywords inputDim objStream As ADODB.StreamSet objStream = New ADODB.Stream' Dim strKeywordForSearch As String' Dim strXML As String' Set objStream = CreateObject("ADODB.Stream")objStream.OpenobjStream.WriteText strXML, adWriteChar 'Give the XML string to the ADOstreamobjStream.Position = 0 'set the stream position to the startDim objRecordset As ADODB.RecordsetSet objRecordset = New ADODB.RecordsetobjRecordset.Open objStream 'Open a recordset from the stream but whenrun, error occured:'Run-time error'2147467259(800004005)''Recordset cannot be created. Source XML is incomplete or invalid.'And the objRecordset has nothing in its field(count=0)' msgbox(objstream.MsgBox (strXML)' Search the recordset by strKeywordForSearchobjRecordset.Filter = strKeywordForSearch' Save recordset to objstreamobjRecordset.save objStream, adPersistXML' Give XML string the filterd valuestrXML = objStream.ReadTextobjStream.CloseSet objStream = NothingxmlSearchBy = strXMLEnd FunctionPublic Function xmlOrderBy(strKeywordForOrder As String) As StringOn Error Resume NextDim objStream As New ADODB.Stream' Dim strKeywordForOrder As StringDim strXML As String' Set objStream = CreateObject("ADODB.Stream")objStream.OpenobjStream.WriteText strXML 'Give the XML string to the ADO streamobjStream.Position = 0 'set the stream position to the startDim objRecordset As ADODB.RecordsetSet objRecordset = New ADODB.RecordsetobjRecordset.Open objStream 'Open a recordset from the streamMsgBox (strXML)' Order based on the keywords inputobjRecordset.Sort = strKeywordForSearch' Save the recordset to objStreamobjRecordset.save objStream, adPersistXML' give the XML string the sorted valuestrXML = objStream.ReadTextobjStream.CloseSet objStream = NothingxmlOrderBy = strXMLEnd FunctionBut now the keywords,strXML have right value while the stream cannot storethem!(the stream pretends to be empty!)can you help me to work out the problem?Thanks a lot!Guan zhen
 
Back
Top