XMLports – What are they and how to use them

XMLports was introduced with Navision 4.0 – they act like dataports, with a small difference. They can only be used for XML-formatted data and they must by executed from some other routine.

In the XMLport designer – you set up a defined format. Just think of it, as a kind of schema (xsd). You can add Elements and Attributes and in the Properties you can setup the Encoding and the DefaultNamespace.

xmlport_designer

Now that the XMLport has been designed, it is time to use it.

An XMLport, can as already mentioned, not be executed by itself. You have to call it from another routine. Such as a codeunit, forms etc.

To export XMLs do the following:

First create an Out File - this are what you xml will be called:

      outFile.CREATE('c:\outxml.xml');

Next prepare for streaming the data to XML. In Designer example we used 
Sales Header. So the out stream is called SH_outStream:

      outFile.CREATEOUTSTREAM(SH_outStream);

Now that we have the out File and the out stream ready it is time to execute
the XMLport. This is done by calling the export:

      XMLPORT.EXPORT(50000, SH_outStream);

And then finally end by closing the file.

      outFile.CLOSE;

The exported XML file will look like this:

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<invoice>
    <sales_header>
        <document_no>2001</document_no>
        <sell-to_customer>10000</sell-to_customer>
        <sales_lines>
            <sales_line>
                <itemno quantity="4" price="0">ITEM-No-10</itemno>
                <description>This is a item description</description>
            </sales_line>
        </sales_lines>
    </sales_header>
</invoice>

Importing XML files is similar to the Export:

First open the file:

      inFile.OPEN('c:\inxml.xml');

Next create an in stream:

      inFile.CREATEINSTREAM(SH_inStream);

And then execute the XMLport to importing the xml:

      XMLPORT.IMPORT(50000, SH_inStream);

And then finally end by closing the file:

      inFile.CLOSE;

That’s all – now you can export and import xml files using an XMLport.

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.