XML parser- Determine Entity Fields Types Using .ol-xml.yml

While parsing an XML file, the entity could be generated not as expected because we can't predict if the XML label should be a collection or a structure.
For this reason, we must adjust the XML parser and determine the type for each label.
To do this, you must update the .ol-xml.yml file in the root of its SDK project and specify a chain of elements in accordance with their type.

How to work with .ol-xml.yml

.ol-xml.yml - is configuration file for XML parser. Allows extending parser functionality in accordance with user-specific cases, related to XML structure.

Consists of:

  • typeAttribute - defines a specific element attribute name, that describes value type.

  • types - defines the mapping between XML and Java types.

  • primitives - defines a set of XML paths, related to primitive values.

  • structures - defines a set of XML paths, related to struct values.

  • collections - defines a set of XML paths, related to primitive values.

Type detection

TypeAttribute

There's no way to detect type by its value. I.E. 1554731001000 may present several types like Long, Double, Date, or String. To avoid it, some XMLs provide a specific attribute, that defines type of value. I.E.

For example:

<element type="long">1554731001000</element>

In this case, the attribute called type and it should be provided in ol.xml.yml as:

typeAttribute: type

In cases, when property not set, the parser will generate all values as string.

Types

There`s no way to detect Java type, by typeAttribute value. To avoid it, you should provide all mappings between XML and Java types. I.E.

For example:

... <one type="int">1</one> <two type="two">two</two> ...

In this case, there are two types: int and two, that should be provided in ol.xml.yml as:

Note: typeAttribute and types-properties are related to primitive elements.

XML trees

Xml tree consists of primitive, structure, and collection elements. There`s no way to detect element type correctly. I.E.

For example:

In this example root.element may be primitive or structure and root may be an array.

To avoid mismatch you should map XML paths with element types.

Primitives

Primitives contain XML paths, related to primitives.
Primitive - element with value.

For example:

root.one has value, root.two may present empty value. Paths should be provided in ol-xml.ymlas:

In cases when XML path not provided, the parser will detect element as primitive, when it has not any subfield.

Structures

Structure Contains XML paths, related to structures.
Structure - element without value, may have sub-elements.

For example:

root.structure1 has sub-elements and has no value, root.structure2 may present an empty structure. Paths should be provided in ol-xml.yml as:

collections

Collection contains XML paths, related to collections.
Collection - element without value, that has 1..N children with the same name.

root.array should be provided in ol-xml.yml as:

 

For a simple example:
https://openlegacy.atlassian.net/l/c/r8A1F1ro