Xml

  • 04 Oct

    How to move directories by sending an xml to a watch folder

    How to move directories by sending an xml to a watch folder

    Q: I want to move directories recusivly from one volume to another, by sending an xml to a watch folder.

    <Move>
    <Dir Src=”C:\Test\Label\In Dest=”C:\Test\Label\Out/>
    </Move>
    This moves all files and subdirectories from the source to destination, every time I drop a new file into the processing folder. Each xml will contain one entry (Src and Dest). When a xml file is successfully processed it should go to a ‘backup’ folder.
    A: Yes, this should be possible using our Pascal Script option. We’ll read the ‘Scr’ and ‘Dest’ value from the xml, the function and other settings need to be done within our File Mover. Both Src and Dest should be Windows folders or shares. We added an option that will move invalid xml files to an ‘error’ folder.
    • We used the following test folder structure:
    limagito file mover move directories by sending an xml
    • The Xml processing folder contains two subfolders:
      • Backup: when a xml file is successfully processed it should go to a ‘backup’ subfolder
      • Error: invalid xml files will be moved to this ‘error’ subfolder

    limagito file mover move directories by sending an xml

    • Source Setup:
      • Variable %VSA ( Variable String A ) will be set using our Pascal Script option

    limagito file mover windows folder as source

    • Destination Setup:
      • Variable %VSB ( Variable String B )will be set using our Pascal Script option

    limagito file mover windows folder as destination setup

    • Open our Pascal Script option:

    limagito filemover pascal script option

    • Enable and add the following ‘On Rule Begin’ Pascal Script:
      • You can download the script here
      • Do not forget to adjust the Const values
        • ctXmlPath: Path where we need to look for xml files
        • ctXmlErrorPath: Path where we will move invalid xml files to
        • ctRoot, ctChild, ctAttrSrc, ctAttrDest: Where do we need to look in the xml files to find ‘Src’ and ‘Dest’ values.

    limagito file mover on rule begin pascal script

    • Enable and add the following ‘On Rule End’ Pascal Script:
      • You can download the script here
      • Do not forget to adjust the Const values
        • ctXmlBackupPath: Path where successfully processed xml files are moved to

    limagito file mover on rule en pascal script

    • RunTime Log Result:
      • We found a valid ‘xml_processor.xml’ file containing ‘C:\Test\Label\In’ as Src and ‘C:\Test\Label\Out’ as Dest

    limagito file mover runtime log result

    If you need any help about this ‘move directories by sending an xml’ request, please let us know.

    Best Regards,

    Limagito Team

    #xml #managedfiletransfer #filetransfer #filemanagement

  • 01 Sep

    Count the number of occurrences of an xml field

    Q: We would like to count the number of occurrences of point X in a xml file and update the file name with that value. Kindly refer the code and validate with sample file attached . Let us know if any details required from us.

    • Input file Name: 12345678.3959-2024.04.25-08.20.30-WIT-signed.xml
    • Generated Output file Name : 12345678.3959-2024.04.25-08.20.30-WIT-signed.79.xml

    Content example xml file:

    limagito file mover C:\Users\coene\Downloads\Count the number of occurrences\count the number of occurrences

    A: Please have a look at the following screenshots:

    • We added the floowing WIN as Source:

    limagito file mover windows folder as source

    • Please open our Pascal Script option:

    limagito file mover pascal script option

    • Enable and Add the following On Destination Pascal Script:

    Link to Script, we are using the psVIA (Pascal Script Variable Integer A, = %VIA parameter):

    limagito file mover count the number of occurrences

    • Destination Setup, we added an Windows Folder as Destination:

    limagito file mover destination setup

    • Destination File Rename Setup:

    limagito file mover file rename setup

    As replacement parameter we’ll use the value of %VIA (= psVIA which we obtained previously in our Pascal Script):

    RegEx: (.*)\.(.*)
    Replacement:  \1.%VIA.\2
    limagito file mover file renaming setup
    – RunTime Log Result:
    limagito file mover runtime log result

    If you need any help with this ‘count the number of occurrences of a xml field’ request, please let us know.

    Best Regards,

    Limagito Team

    #xml #managedfiletransfer #filetransfer #filemanagement

  • 31 May

    How to convert from XML to JSON format

    Q: We receive some files in XML format. Could you please confirm, if Limagito tool can convert XML files to JSON format? If yes, Do we have any limitations while converting the file type? Please let us know if you need any additional information.

    A: We added an option in version v2023.5.31.0 to achieve this.

    • Our Source will be a Windows folder

    limagito file mover Windows folder as source

    • We added the following include Filename filter because we only want to scan for *.xml files:

    limagito file mover filename filter

    • We’ll need a Pascal Script to convert the xml file to a Json file so we added Pascal Script as Destination:

    limagito file mover destination setup

    • We noticed that the xml we received from the customer was not a valid xml so we added some extra code (line 18) in the script to adjust this

    limagito filemover xml to json

    • Pascal Script we used (don’t forget to adjust the ctOutputPath const):
    Var
     tmpFileInput, tmpFileOutput, tmpResult: String;
     tmpXmlText: String;
     tmpList: TStringList;
    Const
      ctOutputPath = 'C:\Test\Out_JSon\'; // Must end with a \ 
    Begin
      // Init Var
      tmpFileInput := psFilePath + psFileName;
      tmpFileOutput := ctOutputPath + ChangeFileExt(psFileName, '.Json');
      psExitCode:= 0;
      // Read non valid Xml file and adjust before creating Json File
      tmpList := TStringList.Create;
      Try
        Try
          tmpList.LoadFromFile(tmpFileInput);
          tmpXmlText := tmpList.Text;
          tmpXmlText := psStringReplace(tmpXmlText, '-&lt;', '&lt;'); // Adjust Non Valid Xml
          // psLogWrite(1, '', 'StringReplace Xml Result: ' + tmpXmlText); // Debug
          tmpResult := psXmlTextToJSonFile(tmpXmlText, tmpFileOutput, True, True, True, True);
          If tmpResult = '' Then
          Begin
            psLogWrite(1, '', 'Saved Json Data to ' + tmpFileOutput);      
            psExitCode := 1;
          End  
          Else
            psLogWrite(1, '', tmpResult);
        Except
          psLogWrite(1, '', 'Load Xml from ' + tmpFileInput + ' Exception');
        End;
      Finally
        tmpList.Free;
      End;
    End.

    limagito file mover convert from xml to json

    In the example above we used The following function:

    Function psXmlTextToJSONFile(Const aXmlText, aJsonFile: String; Const aXmlParse, aXmlPack, aJsonIndent, aJsonEscape: Boolean): String;

    The psXML functions have a aXmlPack option that determines the format returned, Pack = False returns all tags as values with multiple nested levels of objects, Pack = True is simpler and easier to process but does lose some tag names.

    aXmlPack = False : all XML content is converted into Json values, each level with two or three names: #attributes is an optional object from opening tag, #Name
    is the string from <Tag>, and #children which is an array of other Json objects and arrays nested within the tag.

    aXmlPack = True : tags are converted to Names and their content to Values, or nested objects. For a single record, a single object is returned with the tag names
    lost, for multiple records (ie tags of the same name) an array is created with each record being an object.

     

    • RunTime Log Result:

    limagito file mover xml to json runtime log result

    • Json File Result:

     

    limagito filemover xml to json

    • Another available Pascal Script function that can be used only when source xml is valid (direct file to file conversion):

    Function psXmlFileToJSONFile(Const aXmlFile, aJsonFile: String; Const aXmlPack, aJsonIndent, aJsonEscape: Boolean): String;

    • Pascal Script will result in:
    Var
     tmpFileInput, tmpFileOutput, tmpResult: String;
    Const
      ctOutputPath = 'C:\Test\Out_JSon\'; // Must end with a \ 
    Begin
      // Init Var
      tmpFileInput := psFilePath + psFileName;
      tmpFileOutput := ctOutputPath + ChangeFileExt(psFileName, '.Json');
      psExitCode:= 0;
      // Xml File To JSon File
      tmpResult := psXmlFileToJSonFile(tmpFileInput, tmpFileOutput, True, True, True);
      If tmpResult = '' Then
      Begin
        psLogWrite(1, '', 'Saved Json Data to ' + tmpFileOutput);  
        psExitCode := 1;
      End  
      Else
        psLogWrite(1, '', tmpResult);
    End.
    

    limagito file mover convert from xml to json

    #filetransfer #mft #filemanagement #xml #json

    If you need any info  about this ‘Convert from XML to JSON format’ request, please let us know.

    Best regards,

    Limagito Team

1 2
SEARCH