Home > OS >  How to Load Xml File in Business Central
How to Load Xml File in Business Central

Time:07-22

I have a below code in NaV 13 and i want to write same logic in business central on SAAS.

Xmldoc:= xmldoc.xmldocument; xmldoc.load(FileName);

Xmldoc is dot net variable in navision. How can i write same login in business central on saas as dot net variables are not available on saas.

CodePudding user response:

First you need to upload the file content to an InStream.

You can do this with the UploadIntoStream procedure:

UploadIntoStream('*.xml', XmlInStream);

XmlInStream is a variable of type InStream.

Next you need to use the new XML data types to load the XML Document from the stream:

XmlDocument.ReadFrom(XmlInStream, MyXmlDocument);

MyXmlDocument is a variable of type XmlDocument.

You can then start processing the XML Document through the MyXmlDocument variable and the use of the XML data types.

CodePudding user response:

Since I do not know specifically how you are using it this might not answer your question directly, but it should point you in the right direction.

This is one way to upload an XML file to a variable in Business Central. More information on the XmlDocument Data Type can be found in the docs

local procedure XMLImportFunction()
var
    Ins: InStream;
    FileName: Text;
    XmlDoc: XmlDocument;
    Root: XmlElement;
begin
    if UploadIntoStream('Import File', '', '', FileName, InS) then begin
        if XmlDocument.ReadFrom(InS, XmlDoc) then begin
            XmlDoc.GetRoot(Root);
        end;
    end;
end;
  • Related