谢谢:)

解决方案 »

  1.   

    Delphi 里面有TXMLDocument控件,可以用来读取XML 文件。使用很简单的,你可以看看一下帮助就是了。
      

  2.   

    unit uXMLToSQL;interface
    uses
      classes, ComObj, DB, dxmdaset, SysUtils, ComCtrls;
    type
      TXMLAnalyse = class
      private
        oDoc: OleVariant;
        FBillNo: string;
      public
        constructor create(xml: widestring);
        destructor Destroy; override;
        function Execute: TStringList;
        property BillNo: string read FBillNo;
      end;
    implementation{ TAnalyse }constructor TXMLAnalyse.create(xml: widestring);
    begin
      oDoc := CreateOleObject(MSXMLDOC);
      oDoc.LoadXML(xml);
    end;destructor TXMLAnalyse.Destroy;
    begin  inherited;
    end;function TXMLAnalyse.Execute: TStringList;
    var
      oNode: OleVariant;
      oFieldsNode, oRowsNode: OleVariant;
      oFieldItem, oRowItem: OleVariant;
      strTableName: string;
      strFieldName: string;
      strValue: string;
      strTmp: string;
      strDel: string;
      strBillNo: string;
      strInsertSQL: string;
      strList: TStringList;
      strAccount: string;
      j, i: integer;
    begin  strList := TStringList.create;  oNode := oDoc.documentElement;
      //得到表名
      strTableName := oNode.getAttribute('Name');
      //得到字段名
      i := pos(':', strTableName);
      if i > 1 then
      begin
        strAccount := copy(strTableName, i + 1, length(strTableName) - i);
        strTableName := copy(strTableName, 0, i - 1);
      end;
      if oNode.childNodes(0).nodeName <> 'Fields' then exit;
      if oNode.childNodes(1).nodeName <> 'Rows' then exit;  oFieldsNode := oNode.childNodes(0);
      oRowsNode := oNode.childNodes(1);  for j := 0 to oFieldsNode.childNodes.length - 1 do
      begin
        oFieldItem := oFieldsNode.childNodes(j);
        strTmp := oFieldItem.getAttribute('fName');
        strFieldName := strFieldName + strTmp + ',';
      end;
      strFieldName := copy(strFieldName, 1, length(strFieldName) - 1);  for j := 0 to oRowsNode.childNodes.length - 1 do
      begin
        oRowItem := oRowsNode.childNodes(j);
        strValue := '';    for i := 0 to oRowItem.Attributes.length - 1 do
        begin
          strValue := strValue + '''' + oRowItem.Attributes(i).text + '''' + ',';      if UpperCase(oRowItem.Attributes(i).name) = 'BILLNO' then
            strBillNo := oRowItem.Attributes(i).text;
        end;
        strValue := copy(strValue, 1, length(strValue) - 1);
        strInsertSQL := 'INSERT INTO ' + strTableName + '(' + strFieldName + ')';
        strInsertSQL := strInsertSQL + ' VALUES(' + strValue + ')';    strList.Add(strInsertSQL);  end;
      if trim(strBillNo) <> '' then
      begin
        strDel := 'DELETE ' + strTableName + ' WHERE  BillNo=''' + strBillNo + '''';
        if UpperCase(trim(strTableName)) = 'BILLMARK_TAB' then
        begin      strDel := strDel + ' and  Account=' + '''' + strAccount + '''';
        end;
        strList.Insert(0, strDel);
      end;
      Result := strList;
      FBillNo := strBillNo;end;end.
      

  3.   

    可以用clientdatabase的loadfromfile来读取xml的,再用dbgrid可以显示出来的
      

  4.   

    用clientdatabase的loadfromfile来读取xml,clientdataset不能释放数据,也就是第一可以读出,得用同一个clientdataset则不能再正确读出数据,也就是读出的还是前一次的数据!关注!!!