XML

  • 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

  • 05 Nov

    How to adjust text in a xml file

    How to adjust text in a xml file

    Q: How can I setup a watch folder for any xml files come in and search for specific wording and change it to another word and move it out to an output directory.

    For the attach example:

    • If you see the word “  <Main>1</Main>”  then change to <Main>Good</Main>
    • If you see other word beside “1” then chang to <Main>NoGood</Main>

    Example content:

    <?xml version=”1.0″?>
    <Header>
    <Main>1</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    A: Yes this is possible using ‘Pascal Script’ as Destination.

    Source is a Windows folder:

    limagito file mover windows folder as source

    We adjusted the ‘Include Filename Filter’ to *.xml because we only want to handle xml files here.

    limagito filemover include filename filter

    We added our ‘Pascal Script’ option as Destination:

    limagito file mover pascal script as destination

    We added the following script. Please do not forget to adjust the ctOutputPath const which must end with a \

    You can download the script: here

    limagito file mover adjust text in a xml file

    RunTime Log result:

    limagito file mover runtime log result

    Content of the 3 source test files we used:

    1. TEST.Good.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>1</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    2. TEST.NoGood.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>0</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    3. TEST.NoGood.blanc.xml

    <?xml version=”1.0″?>
    <Header>
    <Main></Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    Content of the 3 resulting Destination files:

    1. TEST.Good.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>Good</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    2. TEST.NoGood.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>NoGood</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    3. TEST.NoGood.blanc.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>NoGood</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

     

    #xml #filetransfer #filemanagement

    If you need any help with this ‘adjust text in a xml file’ request, please let us know.

    Best Regards,

    Limagito Team

  • 11 Jul

    Generate an xml on output with the same name as the input filename

    Q: I was wondering if Limagito File Mover can generate an xml on output with the same name as the input filename.

    A: Yes this is possible. In this case we’ll add a second Destination. This ‘Pascal Script’ Destination will create the Xml file. It will only generate this xml if the first Destination succeeds.

    1.You can use any Source. In our example we used a Windows Folder.

    2.We only want write the Xml file if the first Destination Succeeds. Therefore we have to select ‘Destination Memory & Exit Cyclus On Error’ as Destination Option in the Function Setup.

    Limagito File Mover Function Setup

    3. Add Pascal Script (PScript) as Second Destination

    Limagito File Mover Pascal Script as Destination

    4. Pascal Script Destination Setup

    We received the following example xml from the user (but we can generate other xml structures too):

    <?xml version=”1.0″ encoding=”iso-8859-1″?>
    <AdWatchData>
    <adwatch-ad-number>HOU4001521801</adwatch-ad-number>
    <file_name>HOU4001521801.pdf</file_name>
    </AdWatchData>

    We created the following Pascal Script which will generate the xml file. Please don’t forget to adjust the ‘ctOutputPath’ Const which will be different in your case. In our example we’ll create the xml file in: ‘C:\Test\Out\’.

    Limagito File Mover generate xml on output

    Var
      tmpFileExt: String;
      tmpFileName, tmpFileNameNoExt: String;
      tmpXml: TStringList;
    Const
      ctOutputPath = 'C:\Test\Out\'; // must end with a \
    Begin
      psExitCode:= 0;
      tmpFileExt := ExtractFileExt(psFileName);
      tmpFilenameNoExt := psStringReplace(psFileName, tmpFileExt, '');
      tmpFileName := tmpFileNameNoExt + '.xml';
      // Create XML
      tmpXml := TStringList.Create;
      Try
        tmpXml.Add('<!--?xml version="1.0" encoding="iso-8859-1"?-->')
        tmpXml.Add('');
        tmpXml.Add('' + tmpFileNameNoExt + '');
        tmpXml.Add('' + psFileName + '');
        tmpXml.Add(''); 
        // Save to File  
        Try
          tmpXml.SaveToFile(ctOutputPath + tmpFileName);
          psExitCode := 1;   
        Except
          psLogWrite(1, '', 'SaveToFile Error, File: ' + ctOutputPath + tmpFileName);
        End;
      Finally
        tmpXml.Free;
      End;  
    End.

    5.RunTimeLog Result:

    Limagito File Mover RunTime Log

    6. Generated Xml on Output:

    Limagito File Mover generate xml on output

    #FileTransfer

    If you need any info about this new ‘Generate an xml on output’ option, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team XML ,
1 2
SEARCH