• delphi XML简单处理


    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Xml.XMLDoc, Xml.xmldom, Xml.XMLIntf,
      Vcl.StdCtrls;
    
    type
      TForm1 = class(TForm)
        Memo1: TMemo;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      IDoc: IXMLDocument;
      Root, N1, N2, N3: IXMLNode;
      I: Integer;
    begin
      IDoc := TXMLDocument.Create(nil);
      IDoc.Active := True;
      Root := IDoc.AddChild('公司');
      for I := 1 to 9 do
      begin
        N1 := Root.AddChild('部门');
        N1.Attributes['Id'] := I;
        N1.AddChild('名称').NodeValue := '部门_'+I.ToString;
        N1.AddChild('主管').NodeValue := '主管_'+I.ToString;
      end;
      IDoc.SaveToFile('d:jjw.xml');
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    var
      Doc: IXMLDocument;
      Node: IXMLNode;
      I: Integer;
    begin
      Doc := TXMLDocument.Create(nil);
      Doc.LoadFromFile('d:jjw.xml');
      Doc.Active := True;
      Node := Doc.DocumentElement;
      for I := 0 to Node.ChildNodes.Count-1 do
        Node.ChildNodes[I].AddChild('人数').NodeValue := IntToStr(I+1);
      Doc.SaveToFile('d:jjw.xml');
    end;
    
    procedure TForm1.Button3Click(Sender: TObject);
    var
      Doc: IXMLDocument;
      Node: IXMLNode;
      I: Integer;
    begin
      Doc := TXMLDocument.Create(nil);
      Doc.LoadFromFile('d:jjw.xml');
      Doc.Active := True;
      Node := Doc.DocumentElement;
      for I := 0 to Node.ChildNodes.Count-1 do
        Node.ChildNodes[I].ChildNodes.Delete(2);
      Doc.SaveToFile('d:jjw.xml');
    end;
    
    procedure TForm1.Button4Click(Sender: TObject);
    var
      Doc: IXMLDocument;
      Root, Node: IXMLNode;
      I: Integer;
    begin
      Doc := TXMLDocument.Create(nil);
      Doc.LoadFromFile('d:jjw.xml');
      Doc.Active := True;
      Root := Doc.DocumentElement;
      for I := 0 to Root.ChildNodes.Count-1 do
      begin
        Node := Root.ChildNodes[I];
        if Node.Attributes['Id']=3 then
          Node.ChildNodes[2].NodeValue := 33333;
      end;
      Doc.SaveToFile('d:jjw.xml');
    end;
    
    end.
  • 相关阅读:
    POJ 3660 Cow Contest (floyd求联通关系)
    POJ 3660 Cow Contest (最短路dijkstra)
    POJ 1860 Currency Exchange (bellman-ford判负环)
    POJ 3268 Silver Cow Party (最短路dijkstra)
    POJ 1679 The Unique MST (最小生成树)
    POJ 3026 Borg Maze (最小生成树)
    HDU 4891 The Great Pan (模拟)
    HDU 4950 Monster (水题)
    URAL 2040 Palindromes and Super Abilities 2 (回文自动机)
    URAL 2037 Richness of binary words (回文子串,找规律)
  • 原文地址:https://www.cnblogs.com/karkash/p/9436496.html
Copyright © 2020-2023  润新知