Skip to main content

Library: XML Utility SL

The library contains function blocks to read and write XML files and XML strings on the controller. The individual elements are stored in an array of structures.

In addition, the library also contains function blocks to search for XML elements.

The library can read and write "well-formed" XML files with UTF-8 or UTF-16 encoding.

. The following XML elements are supported:
  • Standard element: <xxx>aaa</xxx> or <xxx />

  • Attributes in the style: yyy="zzz"

  • Comments: <!-- Comment -->

  • CDATA elements

Each element of the XML file corresponds to a structure of type XMLElement. An array of structures of the type XMLElement is used to represent parts or the entire XML file.

. Structure of the XMLElement data structure:
  • diParentIndex: Position of the parent element in the data array

  • wsName: Name of the element

  • wsValue: Value of the element

  • udiPosition: Position of the element in the file

  • elementType: Type of element (element, attributes, CDATA element, comment)

. Function block: XMLGetElement
  • Reads XML elements

  • Read options

    • Read an element

    • Read all child elements of an element

    • Read all components of an element (subtree)

  • The reading is file-based. This means that individual elements can be read by their position in the file without having to keep the entire document in memory.

. Function block: XMLGetElementAsync
  • Reads XML elements asynchronously

. Function block: XMLFindElement
  • Searches file-based XML elements in a file

  • Search options:

    • Search for element names

    • Search for an attribute with a specific value

    • Read all child elements of the found element

    • Read all components of the found element (tree structure)

    • Configurable start position of the search

. Function block: XMLFindElementAsync
  • Searches XML elements asynchronously (asynchronous search queries)

. Function block: XMLFindElementByStringAsync
  • Searches asynchronously and works like XMLFindElementAsync but with STRING inputs for the search

. Function block: XMLWrite
  • Writes XML files

  • Partial writing of elements is not supported. All elements and their dependencies are always loaded into memory (array of XMLElement).

. Function block: XMLWriteAsync
  • Writes XML files asynchronously and works like XMLWrite

Parameter

Reading of the elements is buffered. The read buffer has to be at least as large as the largest XML element. The maximum size can be changed in the Library Manager by means of the parameter list of the library.

The same applies to the size of strings of the WSTRING type in the XMLElement data structure. The result array is generated outside of the function blocks so that the size can be configured individually.