现有一个xml文件,需要将其中的内容导入数据库(sql 2000),请问需要如何处理?麻烦说的清楚一点,如果只是说用stream、loadfromfile()而没有例子的,抱歉,不能给分!xml文件为recordset.save得到,内容如下:- <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" rs:CommandTimeout="30">
- <s:AttributeType name="C_Emp_id" rs:number="1" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="15" rs:maybenull="false" /> 
  </s:AttributeType>
- <s:AttributeType name="C_Emp_name" rs:number="2" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="8" rs:maybenull="false" /> 
  </s:AttributeType>
- <s:AttributeType name="C_Duty" rs:number="3" rs:nullable="true" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="5" /> 
  </s:AttributeType>
- <s:AttributeType name="C_Dep_id" rs:number="4" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="12" rs:maybenull="false" /> 
  </s:AttributeType>
- <s:AttributeType name="C_Emp_tel" rs:number="5" rs:nullable="true" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="20" /> 
  </s:AttributeType>
- <s:AttributeType name="C_Password" rs:number="6" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="8" rs:maybenull="false" /> 
  </s:AttributeType>
- <s:AttributeType name="C_Power" rs:number="7" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="60" rs:maybenull="false" /> 
  </s:AttributeType>
- <s:AttributeType name="I_rule" rs:number="8" rs:nullable="true" rs:writeunknown="true">
  <s:datatype dt:type="int" dt:maxLength="4" rs:precision="10" rs:fixedlength="true" /> 
  </s:AttributeType>
- <s:AttributeType name="Memo" rs:number="9" rs:nullable="true" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="2147483647" rs:long="true" /> 
  </s:AttributeType>
  <s:extends type="rs:rowbase" /> 
  </s:ElementType>
  </s:Schema>
- <rs:data>
  <z:row C_Emp_id="001" C_Emp_name="李建成" C_Duty="" C_Dep_id="01" C_Emp_tel="" C_Password="123" C_Power="" I_rule="1" Memo="备注" /> 
  <z:row C_Emp_id="002" C_Emp_name="操作员1" C_Duty="" C_Dep_id="01" C_Emp_tel="" C_Password="123" C_Power="10101110111100111111111111111101111001111111111111111111" I_rule="1" Memo="备注" /> 
  <z:row C_Emp_id="003" C_Emp_name="操作员" C_Duty="" C_Dep_id="01010100" C_Emp_tel="" C_Password="123" C_Power="11111111111111111111111111111111111111" I_rule="1" Memo="备注" /> 
  </rs:data>
  </xml>

解决方案 »

  1.   

    dim xmlString as string 
    Dim rs As New ADODB.Recordset
    dim rsUpdate as new adodb.recordset
    Dim xDOM As New MSXML2.DOMDocument40
    dim fd as adodb.fieldxmlstring="..."xDOM.loadXML(SoapClient.GetRs(sTable))   '通过MSXML读入xml内容
    rs.Open xDOM                             '填充记录集rsUpdate.Open "select * from table ",cn,adOpenDynamic,adlockoptimistic '打开一个可写数据库的记录集do while not rs.eof              '循环插入记录
        rsUpdate.addnew
        for each fd in rs.fields
           rsUpdate(fd.name).value=rs.fields(fd.name).value
        next    
        rs.movenext
    looprsUpdate.update
    rsUpdate.close
    你需要ADO2.5以上,MSXML最好2.0以上(我例子中用的4.0)
      

  2.   

    sorry,
    xDOM.loadXML(SoapClient.GetRs(sTable))   '通过MSXML读入xml内容
    这一行应该是
    xDOM.loadXML(xmlstring)   '通过MSXML读入xml内容
      

  3.   

    看了一下,还是要用循环,逐一插入啊!
    这样的话效率低了一点!
    而且数据量、表也比较多!
    能不能用一个语句实现呐?
    就像data restore一样!还有xDOM.loadXML(xmlstring),其中的smlstring是不是xml文件的路径?如果用循环的话,就不用引用MSXML2.DOMDocument40对象了!
    可以这样:
    dim res_source as new adodb.recordset
    dim res_target as new adodb.recordset
    dim fel_source as new adodb.field
    '打开硬盘中的xml文件,文件名为tb_employee.xml
    res_source.open 硬盘中的xml文件
    '打开数据库中的表,表名为tb_employee
    '该表的结构和xml文件一致 
    res_target.open "tb_employee",cn,3,3
    do while not res_source.eof()
       res_target.addnew
        for each fel_source in res_sourde.fields
           res_target(fel_sourde.name).value=res_source.fields(fel_source.name).value
        next    
        res_source.movenext
    loop
      

  4.   

    看到一本书关于XML查询操作的,使用ADODB.Stream对象,不过讲的比较简单.
    也给贴上来:
    1.XML模板查询
    dim strcmdsql as string
    dim res_source as new adodb.recordset
    dim cnn as new adodb.connection
    dim cmd_command as new adodb.command
    dim stm_command as new adodb.streamconst DBGUID_MSSQLXML={5D531CB2-E6ED-11D2-B252-00C04F681B71}
    strcmdsql="< root xmlns:sql='urn:schemas-microsoft-com:xml-sq'>" & _
        vbcrlf & _
        "<sql:query> select * from tb_employee" & _
       "FOR XML AUTO </sql:query>" & vbcrlf &_
       "</root>"stm_command.open
    stm_command.writetext strcmdsql ,adwritechar
    stm_command.position=0
    ''open方法使stream对象可以接收文本,writetext 件文本放在stream中
    ' position 保证下次从文本开头读起cnn.open "provider=sqloledb.1;server=(local);" & _
     "initial catalog=databasename;integrated security=password"
    set cmd_command.activeconnection=cnn
    set cmd_command.commandstream=stm_command 
    cmd_command.dialect=DBGUID_MSSQLXML
    'dialect属性是个全局唯一标志符