web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Parsing European Bank XML

(0) ShareShare
ReportReport
Posted on by 85

Hi Everyone,

I need help parsing the below XML. 

I have tried to implement various techniques mentioned in a number of blogs but i was unsuccessful. 

1423.ER1.PNG

I need the rates of say, USD and GBP. How do I obtain them?

Please help!

Thanks.

*This post is locked for comments

I have the same question (0)
  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    Hi Bharath B J,

    Do you plan to import foreign exchange rates into AX from the ECB?

    Ludwig

  • Bharath B J Profile Picture
    85 on at

    Hi Ludwig Reinhard,

    I'm not intending to import foreign exchange rates into AX.

    I just want to read the values from the XML specified in the image above.

  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    You can use any technique for working with XML files - XMLDocument class in AX, XPath, Linq to XML in C# etc. What did you intend to use and what kind of problem do you have with your implementation?

    By the way, you'll have a better chance to get a sample implementation if you give us the XML file and not just a picture.

  • Bharath B J Profile Picture
    85 on at

    Hi Martin,

    Here is the link for the XML:

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

    I just need rates of say USD and GBP given in the XML.

  • Verified answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    You didn't tell me which approach you wanted, so let me pick my own:

    str url = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
    XmlDocument doc = XmlDocument::newFile(url);
    XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.nameTable());
    XmlNode cube;
    str rate;
    
    nsManager.addNamespace('xref', 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref');
    cube = doc.selectSingleNode("//xref:Cube[@currency='USD']", nsManager);
    rate = cube.attributes().getNamedItem('rate').value();
  • Bharath B J Profile Picture
    85 on at

    Thank you so much Martin!

  • Bharath B J Profile Picture
    85 on at

    Martin,

    It would be really helpful for me if you can give me an overview walk through about the line:

    nsManager.addNamespace('xref', 'www.ecb.int/.../eurofxref&;);

  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    Do you know what is XML namespace?

  • Bharath B J Profile Picture
    85 on at

    Not much. I will go deeper into it and explore.

  • Verified answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    Here you find an introduction to XML namespaces.

    When selecting the element via XPath, it's not enough to specify the element name, you have to identify the namespace as well. Because Cube is defined in the default namespace (by xmlns=http://www.ecb.int/vocabulary/2002-08-01/eurofxref), I added this namespace to the namespace manager and I also defined a prefix for it (xref). When selecting the element, I identify the namespace by the prefix, therefore the full name of the element become xref:Cube.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans