aliazzz h-hermsen

Project Members:


Simple and straightforward XML parsing and composing library, characterized by it's small memory footprint.
This library will be moved under the co5e umbrella, see [#11].


Due to its small footprint it can be used in budget friendly, economic controllers. Since the library is able to read small chunks of files into memory (or write small chunks to disk) the buffer can be any arbitrary size, as defined by the user. This library contains means for

XML Control solution, a simple but very effective FB to compose structured XML tags with or without parameters,
File Control solution, to open/close/read/write files,
(W)StringBuffer solution to compose strings in memory.

The example project now contains an additional application which includes a pretty large demo xml file to demonstrate this behavior.

The maximum memory buffer size (parameter) is set smaller than the xml file size.
One FB gets the recipe names from the file and stores the location in the file where the recipe is.
Another FB can read the children of the recipe. This way not all data has to be parsed, but only the required data. This keeps not only the memory buffer small, but also the structures which contain the data.

Download Library v0.4.0.0

Download Example v0.4.0.0


  1. Initialise
        XML : FB_XMLControl;
        Buffer: STRING(GVL_Param_XmlControl.udiMaxFileSize);
        // or buffer as an array of BYTE
        Buffer: ARRAY [0..GVL_Param_XmlControl.udiMaxFileSize] OF BYTE;

    // call
    XML.pBuffer: = ADR (buffer);
    XML.LenBuffer: = SIZEOF (buffer);
  1. Add your own preferred XML fileheader i.e.:
    <?xml version="1.0" encoding="UTF-8"?>
    // call
    XML.WriteDocumentHeader( '<?xml version="1.0" encoding="UTF-8"?>');
  1. Compose a tag with a parameter:
    <mytag paraname="11"></mytag>
    // call
    XML.newTag(sTagName: = 'MyTag');
    XML.newParameter(Name: = 'ParaName', Parameter: = 11);
  1. Add a value to the tag:
    <mytag> MyText </mytag>
    // call
    XML.newTag(Name := 'MyTag');
    XML.newTagData(TagData :='MyText');
  1. Jump to the beginning of the XML data in the buffer
    // call
  1. Add a comment to the XML in the buffer;
    // call
    XML.newComment(sTagName: = 'MyComment');
  1. Returns the next tag from the current position in buffer;
    // call
  1. Output the parameter of the tag;
    // call
    XML.NextParameter(Parameter: = LastValue);

Feedback: Parameter returns the value found (string)

Usage Examples



    XML           : FB_XMLControl;
    Buffer        : STRING(GVL_Param_XmlControl.MaxFileSize);
    StringBuffer  : FB_StringBuffer;
    FileControl   : FB_FileControl;

// Initialise Buffer
XML.SetBuffer(pString:= ADR(Buffer), iSizeOf:= SIZEOF(Buffer));

// If excists, it opens, else it will be created

// Set ASCII encoding in fileheader
XML.WriteDocumentHeader( '<?xml version="1.0" encoding="us-ascii"?>');

//Create Tags
XML.newTag(Name:= 'configuration');
    XML.newTag(Name:= 'file_info');
        XML.newTag(Name:= 'info');
        //Create Parameters
        XML.newParameter(Name:= 'filename', Value:= 'XMLExample.xml');
        XML.newParameter(Name:= 'software', Value:= 'CODESYS');
        XML.newParameter(Name:= 'timestap', Value:= '6/21/2021 11:08:04 AM');
        XML.newParameter(Name:= 'version', Value:= '3.5.16');
        XML.newParameter(Name:= 'device', Value:= 'ControlWin V3');
        XML.newParameter(Name:= 'solution', Value:= 'None');

//Save buffer to file


To be addressed



to be addressed


to be addressed


  • FB_FileAccess: This function block can open, close, read and save a file from and to a generic PLC memory buffer.
    It can also read a small portions (chunks) of the file from disk to memory which enables you to load larger files in small portions.

  • FB_StringBuffer: Acts as an IO stream buffer for use with FB_XmlControl. Data can be treated as STRING or array of bytes. The stringBuffer can also be used as a basis for other purposes like txt, csv, etc, etc.

  • FB_XmlControl: Organizes Parsing and Composing of XML data.
    Filebuffersize can be set via library parameter (Gvl_Param_XmlControl) default 500_000 bytes

Files do not necessarily need to be in a .xml format so you can use filecontrol to access or write any type of file.
Offcourse parsing and composing via xmlcontrol is only supported for xml formatted files.


Download Library v0.4.0.0

Download Example v0.4.0.0


@timvh for providing partial file reading/parsing