码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-07-20 23:37:43      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:delphi   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至本地数据集

标签:delphi   webservice   xml   

原文地址:http://kaixinbuliao.blog.51cto.com/2567365/1440573

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!