<?xml version="1.0" encoding="UTF-16" ?>
- <Root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" KingDeeNameSpace="ReK3Inventory" xmlns="http://www.kingdee.com/ReK3Inventory">
- <Inventory xmlns="">
<Model>0</Model>
<BillType>010200</BillType>
<Type>1</Type>
<BillID>PIN00015</BillID>
<Year>2004</Year>
<Period>10</Period>
<Date>2004-10-30</Date>
- <Company>
<Number>P0079</Number>
<Name>(1090)a股份有限公司</Name>
</Company>
- <Dept>
<Number>020</Number>
<Name>药品</Name>
</Dept>
- <Emp>
<Number>01</Number>
<Name>张三</Name>
</Emp>
- <Root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" KingDeeNameSpace="ReK3Inventory" xmlns="http://www.kingdee.com/ReK3Inventory">
- <Inventory xmlns="">
<Model>0</Model>
<BillType>010200</BillType>
<Type>1</Type>
<BillID>PIN00015</BillID>
<Year>2004</Year>
<Period>10</Period>
<Date>2004-10-30</Date>
- <Company>
<Number>P0079</Number>
<Name>(1090)a股份有限公司</Name>
</Company>
- <Dept>
<Number>020</Number>
<Name>药品</Name>
</Dept>
- <Emp>
<Number>01</Number>
<Name>张三</Name>
</Emp>
RS.Save "c:\test.xml", adPersistXML
//引用microsoft xml 3.0 类库Dim oXML As New MSXML2.DOMDocumentoXML.Load "c:\test.xml"
RS.Open oXML执行以后rs就有了xml中的记录
Private Sub Command1_Click()
Dim oXML As New MSXML2.DOMDocument
Set adoRS = adoCon.Execute("select * from com_inventory where fperiod=1")
adoRS.save "E:\test.xml", adPersistXML
End Sub打开E盘的test.xml出现如下结果:- <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
- <s:Schema id="RowsetSchema">
- <s:ElementType name="row" content="eltOnly">
- <s:AttributeType name="FID" rs:number="1">
<s:datatype dt:type="int" dt:maxLength="4" rs:precision="10" rs:fixedlength="true" rs:maybenull="false" />
</s:AttributeType>
- <s:AttributeType name="FScreenID" rs:number="2" rs:writeunknown="true">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="20" rs:maybenull="false" />
</s:AttributeType>
- <s:AttributeType name="FType" rs:number="3" rs:writeunknown="true">
<s:datatype dt:type="i2" dt:maxLength="2" rs:precision="5" rs:fixedlength="true" rs:maybenull="false" />
</s:AttributeType>
- <s:AttributeType name="FBillID" rs:number="4" rs:writeunknown="true">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="255" rs:maybenull="false" />
</s:AttributeType>
- <s:AttributeType name="FOrgID" rs:number="5" rs:writeunknown="true">
<s:datatype dt:type="int" dt:maxLength="4" rs:precision="10" rs:fixedlength="true" rs:maybenull="false" />
</s:AttributeType>
- <s:AttributeType name="FOrderID" rs:number="6" rs:writeunknown="true">
<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="255" rs:maybenull="false" />
</s:AttributeType>
- <s:AttributeType name="FYear" rs:number="7" rs:writeunknown="true">
<s:datatype dt:type="i2" dt:maxLength="2" rs:precision="5" rs:fixedlength="true" rs:maybenull="false" />
</s:AttributeType>
- <s:AttributeType name="FPeriod" rs:number="8" rs:writeunknown="true">
<s:datatype dt:type="i2" dt:maxLength="2" rs:precision="5" rs:fixedlength="true" rs:maybenull="false" />
</s:AttributeType>
- <s:AttributeType name="FDate" rs:number="9" rs:writeunknown="true">
<s:datatype dt:type="dateTime" rs:dbtype="timestamp" dt:maxLength="16" rs:scale="3" rs:precision="23" rs:fixedlength="true" rs:maybenull="false" />
</s:AttributeType>因为我上面的XML是金蝶数据交换的一个格式,如果格式不一样引入不进去
Dim cmd As New ADODB.Command
Dim conn As New ADODB.Connection
Dim strmIn As New ADODB.Stream
Dim strmOut As New ADODB.Stream ' Open a connection to the SQL Server.
conn.Open ConnectionString
Set cmd.ActiveConnection = conn ' Build the command string in the form of an XML template.
Dim SQLxml As String
SQLxml = "<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql' >"
SQLxml = SQLxml & "<sql:query>"
SQLxml = SQLxml & " SELECT top 2 CustomerID, CompanyName "
SQLxml = SQLxml & " FROM Customers FOR XML AUTO"
SQLxml = SQLxml & "</sql:query>"
SQLxml = SQLxml & "</ROOT>"
' Set the command dialect to XML.
cmd.Dialect = "{5d531cb2-e6ed-11d2-b252-00c04f681b71}" ' Open the command stream and write our template to it.
strmIn.Open
strmIn.WriteText SQLxml
strmIn.Position = 0 Set cmd.CommandStream = strmIn ' Execute the command, open the return stream, and read the result.
strmOut.Open
strmOut.LineSeparator = adCRLF
cmd.Properties("Output Stream").Value = strmOut
cmd.Properties("Output Encoding").Value = "UTF-8"
cmd.Execute , , adExecuteStream
strmOut.Position = 0 ExecuteTemplate = strmOut.ReadText
End Function
Public Conn As New ADODB.ConnectionPublic tempDoc As MSXML2.DOMDocument 'xml文件
Public tempNode As MSXML2.IXMLDOMNode
Public Root As MSXML2.IXMLDOMElement
Public tempelement As MSXML2.IXMLDOMElement
Public tempattribute As MSXML2.IXMLDOMElement
Public emp As MSXML2.IXMLDOMElementPrivate Sub Command1_Click() '生成一个XML DOMDocument对象
Set tempDoc = New MSXML2.DOMDocument '生成根节点并把它设置为文件的根
Set Root = tempDoc.createElement("employees")
Set tempDoc.documentElement = Root
'在节点上添加多个属性
Call Root.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema")
Call Root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
Call Root.setAttribute("xmlns", "http://www.kingdee.com/ReK3Inventory") Do While Not Rs.EOF
Set emp = tempDoc.createNode(MSXML2.NODE_ELEMENT, "employee", "")
Root.appendChild emp '生成孩子节点添加到根节点上去,并且为这个节点设置一个属性
Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "Employeeid", "")
tempNode.Text = Rs(0)
emp.appendChild tempNode Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "Firstname", "")
tempNode.Text = Rs(1)
emp.appendChild tempNode Set tempNode = tempDoc.createNode(MSXML2.NODE_ELEMENT, "Title", "")
tempNode.Text = Rs(2)
emp.appendChild tempNode
Rs.MoveNext
Loop Dim pi As IXMLDOMProcessingInstruction
Set pi = tempDoc.createProcessingInstruction("xml", "version='1.0' encoding='gb2312'") Call tempDoc.insertBefore(pi, tempDoc.childNodes(0))
'直接保存成文件即可
tempDoc.Save "c:\myTest.xml" Unload MeEnd SubPrivate Sub Form_Load()
Dim strConn As String
strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Northwind;Data Source=LocalHost"
Conn.CursorLocation = adUseClient
Conn.Open strConn If Rs.State <> adStateClosed Then Rs.Close
Rs.Open "Select employeeid,Firstname,Title from employees ", Conn, adOpenStatic, adLockOptimisticEnd Sub