Link to home
Start Free TrialLog in
Avatar of RetroRocker
RetroRocker

asked on

Delphi XE2 Parsing XML with TXMLDocument

Hi
 I am trying to parse an XML file using TXMLDocument and Delphi XE2. I am new to XML with Delphi and having much trouble accessing the attribute values from this file:

http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

I have no trouble reaching the first level <Cube> and can return an IXMLNode instance but I cannot get to anything below that ie. second and third level child nodes (both <Cube>) and their attribute values.

Basically I'm doing this, for example, to get the "time" attribute value from the second level <Cube> ...

      StartingItemNode := XMLDocument.DocumentElement.ChildNodes['Cube'];
      aNode := StartingItemNode;
      sDATE := aNode.ChildNodes['Cube'].Attributes['time'];

... line 1 is fine but sDATE in line 3 is always null.

Please could anyone tell me where this is going wrong ?

thanks and best wishes

RR
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RetroRocker
RetroRocker

ASKER

What can I say ...  a thoroughly detailed, fully working solution ... I am genuinely very grateful :-)
I probably would have continued to struggle with TXMLDocument to parse this file and even now, I have still not found a way to do it. I believe that TXMLDocument is a 'wrapper' for MSXML and I applaud your ingenuity in employing MSXML directly. It seems to have methods which are more suitable for addressing the nodes in this case. With TXMLDocument I still have never been able to get beyond the first level of <Cube> in this file.
Once again, many thanks for your time and effort with this.

RR
Thanks. I'm glad to help you. Yes, this is MS parser - and is fast enough, but depends on external dll (part of windows). But there are more other third part components like this one:
http://www.kluug.net/oxml.php
Look at Performance tab.