zoukankan      html  css  js  c++  java
  • delphi创建和读取xml(xml简单操作举例)

    有关许多接口,会需要通过xml进行数据交换,弄个例子,方便参考

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,XMLDoc,XMLIntf, StdCtrls;

    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
    Xml: TXMLDocument;
    Rootnode,node : IXMLNode;
    begin
    Xml := TXMLDocument.Create(nil);
    // Xml.LoadFromFile('aaa.xml');
    try
    //加入版本信息 ‘<?xml version="1.0" encoding="GB2312" ?> ’
    Xml.Active := True;
    Xml.Version := '1.0';
    Xml.Encoding :='GB2312';

    Rootnode := Xml.CreateNode('CIF_INFO');
    Xml.DocumentElement := Rootnode;
    node := Xml.CreateNode('TXNCODE');
    Rootnode.ChildNodes.Add(node);
    node.Text := '420001';
    node := Xml.CreateNode('RESPCODE');
    Rootnode.ChildNodes.Add(node);
    node.Text := '0000';
    node := Xml.CreateNode('CIFID');
    Rootnode.ChildNodes.Add(node);
    node.Text := '0030209728';
    node := Xml.CreateNode('RESCODE');
    Rootnode.ChildNodes.Add(node);
    node.Text := '0000';
    node := Xml.CreateNode('RESMSG');
    Rootnode.ChildNodes.Add(node);
    node.Text := '';

    Xml.SaveToFile('aaa.xml');
    xml.Active := False;
    showmessage('创建成功!');
    finally
    Xml.Free;
    end;
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    var
    Xml: TXMLDocument;
    Rootnode,node : IXMLNode;
    nodelist:IXMLNodeList;
    b,c,str :string;
    i:Integer;
    begin
    Xml := TXMLDocument.Create(Application);


    try
    Xml.LoadFromFile('aaa.xml');
    Xml.Active := True;

    Rootnode := Xml.DocumentElement;
    nodeList :=Rootnode.ChildNodes;
     for i:=0 to nodelist.Count-1 do
        begin
          if  Rootnode.ChildNodes[i].NodeValue = null then
             begin
               c:='空';
             end
             else
             begin
               c:= Rootnode.ChildNodes[i].NodeValue;
             end;
          str:=str+c+#13#10;
        end;
    //b := Rootnode.ChildNodes[ 'CIFID'].NodeValue;
    Memo1.Lines.Add(str);
    xml.Active := False;
    finally
    Xml.Free;
    end;
    end;
    end.

  • 相关阅读:
    小程序用户拒绝授权地理位置的处理办法
    云开发小程序数据库权限有限,通过云函数修改数据库评论信息
    小程序仿照微信朋友圈点击评论键盘输入
    小程序wx.previewImage查看图片再次点击返回时重新加载页面问题
    js手机端判断滑动还是点击
    Proxy
    Reflect.has检测对象是否拥有某个属性
    简单的axios请求返回数据解构赋值
    为windows terminal 配置 conda
    git clone 遇到问题:fatal: unable to access 'https://github.comxxxxxxxxxxx':
  • 原文地址:https://www.cnblogs.com/cnajian/p/2226262.html
Copyright © 2011-2022 走看看