🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.xml
Article #75

getting parameters from a XML node

#75
From: DelphiGuy
Date: Wed, 09 Jul 2008 00:14
102 lines
3614 bytes
Hi everyone, my name is Luc and I'm currently looking for a way to get a
specific information from this file:

http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml

I need to get the currency and rate from this line:
<Cube currency="USD" rate="1.5687" />

I have a little experience with XML files but I'm used to get information
directly like this line
<gesmes:name>European Central Bank</gesmes:name>

I have joined a short and simple example of how I'm reading XML files and
I'm sure I can add a line or two in this code to get the information I need
in the TravelChildren function but this is beyond my current abilities.

If someone could help me out on this it would be greatly appreciated.   This
code is displaying on a memo field the values of the searched node which in
my case is 'Cube'.

Thank you.



---------------------------------------------------------------------------------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, MSXML2_TLB, comobj;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { D�clarations priv�es }
  public
    { D�clarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
   i,j,ret_val,count : Integer;
   strData : String;
   datalist : tStringList;
   doc : iXMLDomDocument;
   nList : iXMLDomNodeList;

procedure travelChildren(nlist1:IXMLDOMNodeList);
var
   j:Integer;
   temp:String;
begin
    for j:=0 to nlist1.Get_length-1 do begin
       //node type 1 means an entity and node type 5 means EntityRef
       if((nlist1.Get_item(j).Get_nodeType= 1) or 
(nlist1.Get_item(j).Get_nodeType=5)) then
          travelChildren(nlist1.Get_item(j).Get_childNodes)
         //node Type 3 means a text node,
       else if(nlist1.Get_item(j).Get_nodeType=3) then begin
          temp:= trim(nlist1.Get_item(j).Get_nodeValue);
          DataList.Add(temp);
       end
    end;
end;

begin
    count:=1;
    DataList:=TStringList.Create;
    memo1.Clear;
    doc := CreateOleObject('Microsoft.XMLDOM') as IXMLDomDocument;
    doc.load('eurofxref-daily.xml');

    nlist:=doc.getElementsByTagName('Cube');

    for i:=0 to nlist.Get_length-1 do begin
       travelChildren(nlist.Get_item(i).Get_childNodes);

       for j := 0 to datalist.Count - 1 do begin
          memo1.lines.append(datalist[i]);
       end;
       memo1.lines.append('=======(Record no. :'+inttostr(count)+')');

       DataList.Clear;
       count:=count+1;
    end;
end;

end.
 
Technical Details
Message-ID: <487402eb$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!news.isoc.lu!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f5d9b,b32501662a612198,start
X-Google-Attributes: gidf5d9b,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
From: "DelphiGuy" <luc.co@sympatico.ca>
Newsgroups: borland.public.delphi.xml
Subject: getting parameters from a XML node
Date: Tue, 8 Jul 2008 20:14:42 -0400
Lines: 104
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
NNTP-Posting-Host: 70.53.228.147
Message-ID: <487402eb$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1215562475 70.53.228.147 (8 Jul 2008 17:14:35 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!news.isoc.lu!newsgroups.borland.com!not-for-mail