Article View: borland.public.delphi.xml
Article #76Re: getting parameters from a XML node
From: Remy Lebeau (TeamB)
Date: Wed, 09 Jul 2008 22:56
Date: Wed, 09 Jul 2008 22:56
61 lines
2958 bytes
2958 bytes
"DelphiGuy" <luc.co@sympatico.ca> wrote in message
news:487402eb$2@newsgroups.borland.com...
> 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" />
Since you are using MSXML directly, you can perform XPath queries via the
selectNodes() and selectSingleNode() methods instead of iterating the nodes
manually. For example (untested):
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
Doc: IXMLDomDocument2;
List : IXMLDomNodeList;
Node: IXMLDomNode;
Attrs: IXMLDOMNamedNodeMap;
begin
Memo1.Clear;
Doc := CreateOleObject('Microsoft.XMLDOM') as IXMLDomDocument2;
Doc.load('eurofxref-daily.xml');
Doc.setProperty('SelectionLanguage', 'XPath');
Doc.setProperty('SelectionNamespaces',
'xmlns:gesmes=''http://www.gesmes.org/xml/2002-08-01''
xmlns:ecb=''http://www.ecb.int/vocabulary/2002-08-01/eurofxref''');
// to retreive all currencies
List :=
Doc.selectNodes('/gesmes:Envelope/ecb:Cube/ecb:Cube/ecb:Cube');
for i := 0 to List.get_length-1 do
begin
Node := List.get_item(i);
Attrs := Node.get_attributes;
Memo1.Lines.Append(Format('Currency: %s, Rate: %s',
[Attrs.getNamedItem('currency').get_text,
Attrs.getNamedItem('rate').get_text]);
end;
// to retreive USD currency only
Node :=
Doc.selectSingleNode('/gesmes:Envelope/ecb:Cube/ecb:Cube/ecb:Cube[@currency="USD"]');
if Node <> nil then
Memo1.Lines.Append('USD Currency is: ' +
Node.get_attributes.getNamedItem('rate').get_text);
end;
Refer to MSDN for more details:
XPath Reference
http://msdn.microsoft.com/en-us/library/ms256115.aspx
Gambit
Technical Details
Message-ID:
<48754285$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<487402eb$2@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f5d9b,b32501662a612198 X-Google-Attributes: gidf5d9b,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.delphi.xml References: <487402eb$2@newsgroups.borland.com> Subject: Re: getting parameters from a XML node Date: Wed, 9 Jul 2008 15:56:35 -0700 Lines: 64 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 207.178.157.90 Message-ID: <48754285$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1215644293 207.178.157.90 (9 Jul 2008 15:58:13 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail