Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Magno's Blog / Weekly exchange rate update...

Weekly exchange rate update (using DotNet)

Community Member Profile Picture Community Member

A while ago, I posted a blog post to download the exchange rates from ECB.

Someone replied that the code is using automations, which do not longer work as of NAV 2013. In this post, I will just do the same, except using DotNet variables this time.

XmlTextReader := XmlTextReader.XmlTextReader('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');

WHILE XmlTextReader.Read DO BEGIN
  IF XmlTextReader.Name = 'Cube' THEN BEGIN
    IF XmlTextReader.AttributeCount = 1 THEN BEGIN
      XmlTextReader.MoveToAttribute('time');

      EVALUATE(intYear,COPYSTR(XmlTextReader.Value,1,4));
      EVALUATE(intMonth,COPYSTR(XmlTextReader.Value,6,2));
      EVALUATE(intDay,COPYSTR(XmlTextReader.Value,9,2));
      datValueDate := DMY2DATE(intDay,intMonth,intYear);
      
    END;

    IF XmlTextReader.AttributeCount = 2 THEN BEGIN
      XmlTextReader.MoveToAttribute('currency');
      codCurrency := XmlTextReader.Value;

      XmlTextReader.MoveToAttribute('rate');
      EVALUATE(decRate,CONVERTSTR(XmlTextReader.Value,'.',','));

      MESSAGE('%1 - %2',codCurrency,decRate);

    END;

  END;
END;

These are the variables.

Name	DataType	Subtype	Length
XmlTextReader	DotNet	System.Xml.XmlTextReader.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
codCurrency	Code	20
decRate	        Decimal		
datValueDate	Date		
intYear	        Integer		
intMonth	Integer		
intDay	        Integer		
intNodeCounter	Integer

As you can see, there is no more XmlDocument nor XmlHTTP nor …

XmlTextReader supports to make a simple request and import the result in a variable which can do all the handling.

Next, we just loop through the XmlTextReader using the Read method and processing were necessary.

It might not be the best way to loop the file, but you get the picture.

Comments

*This post is locked for comments