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.
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.
XMLElement
data structure:diParentIndex
: Position of the parent element in the data arraywsName
: Name of the elementwsValue
: Value of the elementudiPosition
: Position of the element in the fileelementType
: Type of element (element, attributes, CDATA element, comment)
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.
XMLGetElementAsync
Reads XML elements asynchronously
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
XMLFindElementAsync
Searches XML elements asynchronously (asynchronous search queries)
XMLFindElementByStringAsync
Searches asynchronously and works like
XMLFindElementAsync
but withSTRING
inputs for the search
XMLWrite
Writes XML files
Partial writing of elements is not supported. All elements and their dependencies are always loaded into memory (array of
XMLElement
).
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.
Tip
See the example: Using the XML Utility SL Library.