首页 > 代码库 > 访问webservice,导入xml至本地数据集

访问webservice,导入xml至本地数据集

  1. 创建本地数据集

     clientdataset2.FieldDefs.Clear;;
      with clientdataset2.FieldDefs.AddFieldDef do
      begin
        Name := ‘id‘;
        Size := 10;
        DataType := ftString;
      end;
      with clientdataset2.FieldDefs.AddFieldDef do
      begin
        Name := ‘xm‘;
        size := 10;
        DataType := ftstring;
      end;
      with clientdataset2.FieldDefs.AddFieldDef do
      begin
        Name := ‘xb‘;
        Size := 10;
        DataType := ftString;
      end;
      with clientdataset2.FieldDefs.AddFieldDef do
      begin
        Name := ‘nl‘;
        DataType := ftinteger;
      end;
      with clientdataset2.FieldDefs.AddFieldDef do
      begin
        Name := ‘sfzh‘;
        Size := 10;
        DataType := ftString;
      end;
      with clientdataset2.FieldDefs.AddFieldDef do
      begin
        Name := ‘jtzz‘;
        size := 30;
        DataType := ftstring;
      end;
      clientdataset2.CreateDataSet;
      clientdataset2.open;

  2. 导入xml

    var
      xml:Tnativexml;
      root: TsdElement;
      i:integer;
      ////////////声明soapheader
      aIntf: DataCenterServicesSoap;
      Headers: ISOAPHeaders;
      H: SecuritySoapHeader2;//SecuritySoapHeader2;
    begin
      Try
        clientdataset2.EmptyDataSet;
        xml := Tnativexml.Create(nil);

        ////////////////////////////////////////////////////发送soapheader
        aIntf := (httprio1 as DataCenterServicesSoap);

        H := SecuritySoapHeader2.Create;
        h.Ticket := ‘BE2E4F35-CDE9-46A1-844B-9FB2546491B2‘;

        Headers := (aIntf as ISOAPHeaders);
        Headers.Send(H); //发送Soap Header
       // xml.ReadFromString((httprio1 as DataCenterServicesSoap).getdataasxml(memo1.Text));
        //aIntf.GetInfo; //调用服务
        xml.ReadFromString((httprio1 as DataCenterServicesSoap).GetXML(memo1.Text));
        xml.XmlFormat := xfReadable;
        root := xml.Root;
        for i := 0 to root.NodeCount - 1 do
        begin
          clientdataset2.Append;
          clientdataset2.FieldByName(‘id‘).Value := root[i].NodeByName(‘ID‘).Value;
          clientdataset2.FieldByName(‘xm‘).Value := root[i].NodeByName(‘xm‘).Value;
          clientdataset2.FieldByName(‘xb‘).Value := root[i].NodeByName(‘xb‘).Value;
          clientdataset2.FieldByName(‘nl‘).Value := root[i].NodeByName(‘nl‘).Value;
          clientdataset2.FieldByName(‘sfzh‘).Value := root[i].NodeByName(‘sfzh‘).Value;
          clientdataset2.FieldByName(‘jtzz‘).Value := root[i].NodeByName(‘jtzz‘).Value;
          clientdataset2.Post;
        end;
      finally
        aIntf := nil;
      End;

      xml.Free;
      H.Free;

本文出自 “一切有为法,如梦幻泡影” 博客,请务必保留此出处http://kaixinbuliao.blog.51cto.com/2567365/1440573

访问webservice,导入xml至本地数据集