大悟还俗

邮箱 key_ok@qq.com 我的收集 http://pan.baidu.com/share/home?uk=1177427271
posts - 236, comments - 8, trackbacks - 0, articles - 0
  新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

delphi读取xml文件

Posted on 2013-11-18 17:15 大悟还俗 阅读(...) 评论(...) 编辑 收藏
  功能:  根据省份更新地市信息
-------------------------------------------------------------------------------}
procedure TForm.GetCityInfo;
var
  iXMLAreaFile : IXMLDocument;
  sFileName,aProvince,sProvince,sCity : string;
  nCol,nNum,nCityCount,nprovinceCount : Integer;
begin
  iXMLAreaFile := TXMLDocument.create(nil);
  sFileName :=  getexepath + 'Province.xml';
  iXMLAreaFile.FileName := sFileName;
  iXMLAreaFile.active := True;
  sProvince := cbbprovince.Text;
  if sProvince = '全部' then
  begin
    cbbcity.Items.Clear;
    cbbcity.Items.Add('全部');
    cbbcity.ItemIndex := 0;
  end
  else
  begin
    cbbcity.Items.Clear;
    cbbcity.Items.Add('全部');
    cbbcity.ItemIndex := 0;
    nprovinceCount := iXMLAreaFile.DocumentElement.childnodes.Count;
    for nNum := 0 to nprovinceCount-1 do
     begin
       //获取province节点内容
       aProvince := iXMLAreaFile.DocumentElement.ChildNodes[nNum].
       AttributeNodes[0].nodevalue;
       if aProvince = sProvince then
       begin
         ncityCount := iXMLAreaFile.DocumentElement.childnodes[nNum].childnodes.Count;
         //获取市级节点内容
         for nCol := 0 to ncitycount-1 do
         begin
           sCity := iXMLAreaFile.DocumentElement.ChildNodes[nNum].
           childnodes[nCol].AttributeNodes[0].nodevalue;
           cbbCity.Items.Add(sCity);
         end;
       end;
     end;
  end;
end;
View Code