起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 111|回复: 1

[请求]xml**

[复制链接]
发表于 2008-3-4 16:47:59 | 显示全部楼层 |阅读模式
下面是xml文档和用delphi解析的函数,想问一下在平台中相对应的函数是什么?我想通过下面那段代码解析xml文件,然后写到相应的数据集里。比如:LoadFromFile,NodeName。。这些在平台里怎么表示?能不能把下面那段delphi代码翻译成平台上的函数,谢谢
XML文件内容;
<?xml version="1.0" encoding="GB2312"?>
-<LXSB>
    -<XM>
        <BIGCLASS>654</BIGCLASS>
        <SMALLCLASS>100</SMALLCLASS>
        <SBWH/>
    </XM>

    -<HT>
        <HTNo>ht2008001</HTNo>
          <HTClass>d</HTClass>
          <HTBZ />
        - <HTMX>
                 <MXHTNo>ht2008001</MXHTNo>
                 <HTProNam>2</HTProNam>  
          </HTMX>

   </HT>
</LXSB>

=====================================
type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    XMLDocument1: TXMLDocument;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  myxm = class
    bigclass: string;
    smallclass: string;
    sbwh: string;
  end;
  myhtmx:=class
    mxhtno:string;
    htpronam:string;
  end;
  myht:=class
    htno:string;
    htclass:string;
    htbz:string;
    mx:myhtmx;
  end;
var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  root: IXMLnode;
  lei: IXMLNode;
  info: IXMLNode;
  mxinfo:IMLNode;
  book: mybook;
  i: integer;
begin
  xmldocument1.LoadFromFile('xml.xml');
  root := xmldocument1.DocumentElement;

  lei := root.ChildNodes.First;
  while lei <> nil do
  begin
    if lei.NodeName = 'XM' then
    begin
      xm_t := myxm.Create;

      info := lei.ChildNodes.First;

      while info <> nil do
      begin
        if info.NodeName = 'bigclass' then
          xm_t.bigclass := info.Text
        else if info.NodeName = 'smallclass' then
          xm_t.bigclass := info.Text
        else if info.NodeName = 'sbwh' then
          xm_t.sbwh := info.Text;
        info := info.NextSibling;
        //showmessage('==xm==');
      end;
      memo1.Lines.Add(xm_t.bigclass + xm_t.smallclass + xm_t.sbwh);
    end;
    if lei.NodeName = 'HT' then
    begin
      ht_t := myht.Create;

      info := lei.ChildNodes.First;

      while info <> nil do
      begin
        if info.NodeName = 'htno' then
          ht_t.htno := info.Text
        else if info.NodeName = 'htclass' then
          ht_t.htclass := info.Text
        else if info.NodeName = 'htbz' then
          ht_t.htbz := info.Text
        else if info.NodeName='htmx' then
        begin
          mxinfo:=info.ChildNodes.first;
          while mxinfo<>nil do
          begin
            if mxinfo.NodeName='MXHTNo' then
                ht_t.mx.mxhtno:=mxinfo.text
            else if mxinfo.NodeName='HTProNam' then
                ht_t.mx.htpronam:=mxinfo.text
          end;
        end;
        info := info.NextSibling;
        //showmessage('==ht==');
      end;
      memo1.Lines.Add(ht_t.htno + ht_t.htclass + ht_t.htbz+ht_t.mx.mxhtno+ht_t.mx.htpronam);
    end;
    lei := lei.NextSibling;
  end;

end;

end.
回复

使用道具 举报

发表于 2008-3-4 17:19:00 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-9 03:36 , Processed in 0.036024 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表