Options

Pass XML into function

rickyl76rickyl76 Member Posts: 25
Hi, i have an xml file that i import manually into the system using an xmlport. I then want to convert this whole xml file to text and pass the text to a function. Can someone tell me how i can do this please?

Answers

  • Options
    ftorneroftornero Member Posts: 522
    Hello @rickyl76,

    What version of NAV/BC are you using ?

    Regards.
  • Options
    rickyl76rickyl76 Member Posts: 25
    This is 2016
  • Options
    ftorneroftornero Member Posts: 522
    Hello @rickyl76,

    You could use something like this, the porcediure XML2Text returns a text withe the XMLFile parameter passed:
    OBJECT Codeunit 50050 Pass XML to Text
    {
      OBJECT-PROPERTIES
      {
        Date=09/12/21;
        Time=19:54:40;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                Txt := XML2Text('Your XML File path here');
                MESSAGE(Txt);
              END;
    
      }
      CODE
      {
        VAR
          Txt@1000000000 : Text;
    
        PROCEDURE XML2Text@1000000000(FileName@1000000001 : Text) : Text;
        VAR
          XMLDoc@1000000000 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
        BEGIN
          XMLDoc := XMLDoc.XmlDocument;
          XMLDoc.Load(FileName);
          EXIT(XMLDoc.InnerXml);
        END;
    
        BEGIN
        END.
      }
    }
    

    Regards
  • Options
    rickyl76rickyl76 Member Posts: 25
    Thank you very much for your help
Sign In or Register to comment.