zoukankan      html  css  js  c++  java
  • delphi读XML

    XML文件内容;
    <?xml version="1.0" encoding="GB2312"?>
    <我的书>
        <漫画 作者="小飞">
            <书名>火影忍者</书名>
            <价格>100</价格>
        </漫画>
        <漫画 作者="大飞">
            <书名>死神</书名>
            <价格>100</价格>
        </漫画>
        <漫画 作者="阿斗">
            <书名>天牢</书名>
            <价格>200</价格>
        </漫画>
        <小说 作者="阿斗">
            <书名>天牢</书名>
            <价格>200</价格>
        </小说>
    </我的书>

    ////////////
    delphi内容;
    unit Unit1;

    interface

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

    type
    TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        XMLDocument1: TXMLDocument;
        procedure Button1Click(Sender: TObject);
    private
        { Private declarations }
    public
        { Public declarations }
    end;
    mybook = class
        name: string;
        money: string;
        author: string;
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
    root: IXMLnode;
    lei: IXMLNode;
    info: IXMLNode;

    book: mybook;
    i: integer;
    begin
    xmldocument1.LoadFromFile('xml.xml');
    root := xmldocument1.DocumentElement;

    lei := root.ChildNodes.First;
    while lei <> nil do
    begin
        if lei.NodeName = '漫画' then
        begin
          book := mybook.Create;
          book.author := lei.Attributes['作者'];

          info := lei.ChildNodes.First;

          while info <> nil do
          begin
            if info.NodeName = '书名' then
              book.name := info.Text
            else if info.NodeName = '价格' then
              book.money := info.Text;
            info := info.NextSibling;
            //showmessage('中华人民共和国');
          end;

          memo1.Lines.Add(book.name + book.money + book.author);
        end;
        lei := lei.NextSibling;
    end;

    end;

    end.
  • 相关阅读:
    STM32位带操作
    url参数 加密
    object.key 对象的键排序 可能出现的问题
    在vue项目中 获取容器的高度
    navigator 判断移动端是Android还是iOS
    Nginx下载地址
    Sublime Text3快捷键大全
    鼠标拖着元素飞
    g6 cavans
    vue img标签图片加载时 闪烁
  • 原文地址:https://www.cnblogs.com/ghd2004/p/1274252.html
Copyright © 2011-2022 走看看