Skip to main content

Notifications

Announcements

No record found.

Things i wish i knew when i started working with XML files in AL and Business Central – Part 1

Inge M. Bruvik Profile Picture Inge M. Bruvik 32,744 Moderator

Recently i have done lost of work with handling of XML files in Business Central. I have had many eureka moments while doing this and sometimes really struggled to find good documentation on how to best handle XML files in Business Central. Well there are lots of documentations out there, but i guess it is more correct to say that i struggled to find documentation that was understandable to me given my earlier knowledge of working with XML Documents. So then i thought it would be a good idea to write a series of blog posts trying to cover the things i wish i knew before i started this work. So this is the first part in that series.

The target for this series will be consultants that wants to know a little bit more about how Business Central can handle XML data and also Business Central developers with none or little experience from working with XML in the context of Business Central. If there are specific XML related topics you would like me to cover, please comment below or reach out to me through Twitter or LinkedIn.

From the start i had basic knowledge about how to construct a valid XML document and i kind of expect that you have the same basic knowledge to before you start reading this series.

If you are completely new to XML files and XML data structures i suggest you you find a place to learn the basics. YouTube are full of videos on XML and so is also the rest of the Internet. So do a search in your browser and chose something you think looks good. Personally i think this XML tutorial

Why do you still use XML, isn’t JSON the new kid on the block?

I think some people might start by asking that question. Even though most of the online API’s and web services that are developed today are based on JSON data structures there are still many systems that use XML data structures for exchanging data with other systems. So i think XML data structures will still be with us for a long time. But i will not disagree with people saying that you should also learn how to handle JSON in the context of Business Central. Maybe i will make a series about JSON when i have worked my way through the XML series.

Is XML data necessarily stored in a file?

Very often when people talk about XML they refer to it as XML files. But it is important to understand that XML in reality is a way to structure data and those data structures can be saved in files, but they can also be something you have in the computer memory during processing or it can be stored in some kind of blob storage. Blob is short for binary large object – and are basically a data type that can store a variety of data file types or long text string.
Another very common way to retrieve a XML data set is as a result of a call to a web service that will reply with data formatted as XML. And as more and more systems are moved to the cloud, including Business Central, getting XML data from another resource in the cloud becomes more and more common.

What do we typically use XML for in the context of Business Central?

In Business Central we can use XML data for a lot of things. We can export Business Central data to XML formatted data structures or import XML data into Business Central.

Often are exchange of electronic business documents like invoices, orders and purchase orders exchanged using XML.

XML is also often used for exchanging transactional data with other systems and is also very common when sending and receiving electronic information to and from a bank.

So what does XML data look like?

If you have never seen an XML structure you can look at on below:

<?xml version="1.0" encoding="UTF-8"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

So you can see that even though it is a data format that is not typically designed to be read by humans, it is not so hard to figure out what kind of data an XML structure contains when we look at it.

The basic structure of an XML data structure is Tags represented by the <> signs. And you have an opening tag <> and a closing tag </>. En everything between the opening tag and the closing tag are normally called an XML element.

This was just so we have the very basics before we move in with the series.

What tools do we have in Business Central to work with XML data?

There are several options available for us when we work with XML data in Business Central.

  • XML port – this is the new version of what we in older versions of Dynamics NAV / Navision called a Dataport. We can use the XML Port typically when we want to export or import an XML file from or two Business Central. In my opinion the XML port is best suited for more or less direct import or export where we do not have extensive needs to transform data on the way out or in to Business Central. To be able to use an XML port for import the XML data needs to be stored in an XML file on a disk somewhere.
  • XML Buffer is a tool that is available in the AL programming language. XML Buffer is an easy way to get you started on your XML journey because it more or less lets you work with your XML data in a way that resemble a data table. XML Buffer is basically XML represented in the format of two dimensional data table with records and fields and where every XML element represents one record in the XML Buffer.
  • XML Document is a datatype available in AL. It is basically a wrapper around the XML Document class that you will find in the .net framework. But if you are familiar with using the XML Document in the dot net framework you will discover that XML Documents in AL does not work exactly as you are used to in the .net framework.
  • The Data Exchange Framework – as the name implies this is a framework available for us in Business Central that lets use exchange data with external systems. To some extent it can be configured by the end user without the help of a developer. But it can also be extended or modified on code if necessary. The Data Exchange Framework is well documented by Microsoft, so i will not dig very deep into that during this series.
  • Power Automate may not be the first thing that pops up when people think about handling XML data in Microsoft Dynamics 365 Business Central. But the powerful tools available for us in Power Automate in combination with the Business Central connector can also be well worth to consider. Especially when working in the online version of Business Central.

In the next part we will start by taking a closer look at the XML Port. Please subscribe to the blog if you want to be notified when new parts of this series is being published by inputting your e-mail address in the subscription frame below and hit the subscribe button.

Email Address:

Subscribe


This was originally posted here.

Comments

*This post is locked for comments