Import of complex XML file

Hi all,

I have a quite complex XML file that I need to import into NAV. I have previously used the data exchange framework to import CSV file which basically contained the same information, so naturally I hoped that I would be able to reuse this functionality.

<xml>
    <transactions>
        <transaction date="1525859543">
            <document pdmweid="1920">
                <configuration name="ITEM SUBJECT" quantity="1">
                    <attribute name="Revision" value="D"/>
                    <attribute name="Description" value="Item Description"/>
                    <attribute name="Unit" value="PCS"/>
                    <attribute name="Number" value="ITEM1"/>
                    <attribute name="Type" value="Item"/>
                    <references>
                        <document pdmweid="1197">
                            <configuration name="Default" quantity="1">
                                <attribute name="Revision" value="B"/>
                                <attribute name="Description" value="Item Description"/>
                                <attribute name="Unit" value="PCS"/>
                                <attribute name="Number" value="ITEM2"/>
                                <attribute name="Type" value="Item"/>
                            </configuration>
                        </document>
                        <document pdmweid="1424">
                            <configuration name="Default" quantity="2">
                                <attribute name="Revision" value="B"/>
                                <attribute name="Description" value="Item Description"/>
                                <attribute name="Unit" value="PCS"/>
                                <attribute name="Number" value="ITEM3"/>
                                <attribute name="Type" value="Item"/>
                                <references>
                                    <document pdmweid="1368">
                                        <configuration name="Default" quantity="1">
                                            <attribute name="Revision" value="B"/>
                                            <attribute name="Description" value="Item Description"/>
                                            <attribute name="Unit" value="PCS"/>
                                            <attribute name="Number" value="ITEM30"/>
                                            <attribute name="Type" value="Item"/>
                                            <references>
                                                <document aliasset="" pdmweid="1366">
                                                    <configuration name="Default" quantity="1">
                                                        <attribute name="Revision" value="B"/>
                                                        <attribute name="Description" value="Item Description"/>
                                                        <attribute name="Unit" value="PCS"/>
                                                        <attribute name="Number" value="ITEM31"/>
                                                        <attribute name="Type" value="Item"/>
                                                    </configuration>
                                                </document>
                                                <document aliasset="" pdmweid="1367">
                                                    <configuration name="Default" quantity="2">
                                                        <attribute name="Revision" value="B"/>
                                                        <attribute name="Description" value="Item Description"/>
                                                        <attribute name="Unit" value="PCS"/>
                                                        <attribute name="Number" value="ITEM32"/>
                                                        <attribute name="Type" value="Item"/>
                                                    </configuration>
                                                </document>
                                            </references>
                                        </configuration>
                                    </document>
                                </references>
                            </configuration>
                        </document>
                    </references>
                </configuration>
            </document>
        </transaction>
    </transactions>
</xml>

This is a simplified version of the file. The file could potentially go into levels of elements and sub elements. As the knowledgeable eye can see, then we talk about a multi-level BOM. They need to be imported into job planning lines and whenever an item does not exists in NAV, then it must also create the item and create or modify the assembly BOM.

The file contains two challenges which to my knowledge prevents me from using either XMLPorts or the data exchange framework.

  1. Instead of using unique element names like attributevalue, then it uses . It makes it difficult, if not impossible, to do in XMLPorts and impossible with the standard data exchange framework.
  2. Theoretically the BOM could have unlimited levels, practically we may be able to limit this to 10 or more. I can’t really imagine how to define this in the data exchange framework. If issue 1 is solved, then XMLports could be the answer?

Have any of you worked with such an XML file before? Or just one with attribute name/values instead of elements.

Did you use XMLPorts or data exchange framework?

Of course I could hand code the importing using XMLDOM (dotnet), but would love to avoid that.

We are on NAV 2018.

I used some similar XML structure in one import in the past… but I used XMLDom, I didn’t see how to do it with XMLPorts, I think it’s not possible.

Yes it should be possible both with the XMLDom codeunit and dotnet. I’ve worked a little more with it, and if we limit the number of levels like to 10, then it could be done with XMLPorts. But it’s not going to be beautiful, nor easy to decode. Then XMLDOM with recursive calls is easier.

But I have come to the conclusion that it cannot be done with the data exchange framework.

I will have to get back to the drawing/design table. [emoticon:c4563cd7d5574777a71c318021cbbcc8]

I remember I wrote a very long complicated code for EDI XMl to handle it from NAV and I did it from XML Dom Document class, Nodes, Nodelist and Attributes. It was really not easy to do and you need to pass all nodes as a hard code which are recurring for eg document in the above XML.

But the best part was it executes within a second and populate your NAV Tables.

When I’ve worked with XML files, I used both of them, XMLport, and DOTNET variables. For a simple development, XMLPorts should be enogugh, but working eith DOTNET, is quite more powerfull. It’s true that you may program a bit more, but at the end of the day, you will have more options and capabilities

For simple integrations XMLPorts are fine, even quite complex can be done without a problem. XMLDOM and hand/hardcoding it is great if you have a static formatted document.

But if you have a format which eventually would change, then that’s not best practice, as you would have to re-code a lot of it, if the format changes. Or in this case, if they need to integrate to another PDM (product data management) system with another file format. Here something which like the data exchange framework would be much better, as your file format (description) is just “data”.