2018-09-28 xml 解析

unit Unit3;

interface

uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs,system.json,Vcl.StdCtrls, IdBaseComponent,

  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, Xml.xmldom, Xml.XMLIntf,

  Xml.XMLDoc;

type

TForm3 = class(TForm)

Memo1: TMemo;

Button1: TButton;

    Memo2: TMemo;

    XMLDocument1: TXMLDocument;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);

var

  rNode: IXMLNode;

  I: Integer;

begin

XMLDocument1.LoadFromXML(Memo1.Text);

  rNode := XMLDocument1.ChildNodes.FindNode('UserList');

  if rNode <> nil then begin

    for I := 0 to rNode.ChildNodes.Count - 1 do begin

      if rNode.ChildNodes[I].Attributes['Name'] <> null then

        Memo2.Lines.Add('Name: ' + rNode.ChildNodes[I].Attributes['Name']);

      if rNode.ChildNodes[I].Attributes['ID'] <> null then

        Memo2.Lines.Add('ID: ' + rNode.ChildNodes[I].Attributes['ID']);

      if rNode.ChildNodes[I].ChildNodes.FindNode('Website') <> nil then

        Memo2.Lines.Add('WebSite: ' + rNode.ChildNodes[I].ChildNodes.FindNode('Website').Text);

      if rNode.ChildNodes[I].ChildNodes.FindNode('Intro') <> nil then

        Memo2.Lines.Add('Intro: ' + rNode.ChildNodes[I].ChildNodes.FindNode('Intro').Text);

      memo2.Lines.Add('');

    end;

  end;


{   memo1


I come from hebei.

http://www.desktoptool.net

I come from Shandong.



}






end;

end.

你可能感兴趣的:(2018-09-28 xml 解析)