引用 MS XML v2.6 Dim tempXml(60) As String Dim tempDoc As MSXML2.DOMDocument Dim tempNode As MSXML2.IXMLDOMNode Dim Root As MSXML2.IXMLDOMElement Dim emp As MSXML2.IXMLDOMElement '生成一个XML DOMDocument对象 Set tempDoc = New MSXML2.DOMDocument '生成根节点并把它设置为文件的根 Set Root = tempDoc.createElement("sqs") Set tempDoc.documentElement = Root
Dim pi As IXMLDOMProcessingInstruction Set pi = tempDoc.createProcessingInstruction("xml", "version='1.0' encoding='gb2312'") Call tempDoc.insertBefore(pi, tempDoc.childNodes(0)) '保存文件 tempDoc.Save (App.Path & "\myTest.xml")
参考 http://www.yesky.com/20021016/1635180.shtml或者 Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Private Sub Command1_Click() rs.CursorLocation = adUseClient rs.Open "Select * from students", cn, adOpenStatic, adLockBatchOptimistic MsgBox rs.RecordCount '保存为XML rs.Save "c:\bbb.xml", adPersistXML rs.Close '读取XML文件 rs.Open "c:\bbb.xml", cn, adOpenStatic, adLockReadOnly, adCmdFile MsgBox rs.RecordCount rs.Close End Sub
Dim tempXml(60) As String
Dim tempDoc As MSXML2.DOMDocument
Dim tempNode As MSXML2.IXMLDOMNode
Dim Root As MSXML2.IXMLDOMElement
Dim emp As MSXML2.IXMLDOMElement
'生成一个XML DOMDocument对象
Set tempDoc = New MSXML2.DOMDocument '生成根节点并把它设置为文件的根
Set Root = tempDoc.createElement("sqs")
Set tempDoc.documentElement = Root
'在节点上添加属性
'Call Root.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema")
'生成子节点添加到根节点上去,并且为这个节点设置一个属性
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "wname", "")
tempNode.Text = tempXml(0)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "number", "")
tempNode.Text = tempXml(1)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "year", "")
tempNode.Text = tempXml(2)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "month", "")
tempNode.Text = tempXml(3)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "day", "")
tempNode.Text = tempXml(4)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "qd1", "")
tempNode.Text = tempXml(5)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "qd2", "")
tempNode.Text = tempXml(6)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "qd3", "")
tempNode.Text = tempXml(7)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "qd4", "")
tempNode.Text = tempXml(8)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "qd5", "")
tempNode.Text = tempXml(9)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "qd6", "")
tempNode.Text = tempXml(10)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "qd7", "")
tempNode.Text = tempXml(11)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "qd8", "")
tempNode.Text = tempXml(12)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "pname", "")
tempNode.Text = tempXml(13)
Root.appendChild tempNode
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "phone", "")
tempNode.Text = tempXml(14)
Root.appendChild tempNode
Dim pi As IXMLDOMProcessingInstruction
Set pi = tempDoc.createProcessingInstruction("xml", "version='1.0' encoding='gb2312'") Call tempDoc.insertBefore(pi, tempDoc.childNodes(0))
'保存文件
tempDoc.Save (App.Path & "\myTest.xml")
CSDN网上很多,给你搜一个:
http://search.csdn.net/Expert/topic/1976/1976931.xml?temp=.5075495
介绍一本书:
http://www.china-pub.com/computers/common/info.asp?id=3001
http://www.yesky.com/20021016/1635180.shtml或者
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
rs.CursorLocation = adUseClient
rs.Open "Select * from students", cn, adOpenStatic, adLockBatchOptimistic
MsgBox rs.RecordCount
'保存为XML
rs.Save "c:\bbb.xml", adPersistXML
rs.Close
'读取XML文件
rs.Open "c:\bbb.xml", cn, adOpenStatic, adLockReadOnly, adCmdFile
MsgBox rs.RecordCount
rs.Close
End Sub