<?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>

解决方案 »

  1.   

    'RS为一个recordset对象,前面取数据的代码比较常见,这里省略
    RS.Save "c:\test.xml", adPersistXML
      

  2.   

    读取时的代码
    //引用microsoft xml 3.0 类库Dim oXML As New MSXML2.DOMDocumentoXML.Load "c:\test.xml"
    RS.Open oXML执行以后rs就有了xml中的记录
      

  3.   

    就是这几句就可以搞定,已经很明白了,从数据库取数据到recordset的代码你不会写吗? 随便找本书都会有的,最基本的代码了,自己动动手吧
      

  4.   

    我这样测试了一下
    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是金蝶数据交换的一个格式,如果格式不一样引入不进去
      

  5.   

    是呀,只要能把SQL里面的数据生成我列出的格式就可以了,当然,方便尽量简单呀:)期待中...........
      

  6.   

    晕掉,昨天打不开导航忘了这个帖-_-#http://search.csdn.net/Expert/topic/1976/1976931.xml?temp=5.231875E-02先参考这个
      

  7.   

    给段代码你参考一下,看效果如何:Public Function ExecuteTemplate() As String
        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
      

  8.   

    看这段代码,我把数据改成northwinds中的employees表了Option ExplicitPublic Rs As New ADODB.Recordset
    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
      

  9.   

    这是DOM方法做的,不建议直接用字符串写文件,XLST的,我还得考虑下。