How to write a parsing definition

The main objective of the parser feature is to split a string message in which we know the structure (position based - forward reading) of the different parts.

The structure of the parsing definition is an xml. the basic structure looks like this:
<parser>
   <parts />
   <message>
      <!-- ... -->
   </message>
</parser>

  • parts element : contains templates of the parsing definition that can be reused. This will be explains later.
  • message element : it's the root element that will contain the parsing definition that will be used to parse the string message

Here is the list of elements that can be used inside the message element:
  • field element
  • const element
  • group element (container)
  • loop element (container)
  • switch element
    • case element (container)
    • else element (container)
  • partRef element

Some elements are marked container. It means that the element can contain children.

The field element

This element reads forward a defined number of characters

example : <field label="Postal Code" length="5" id="pcode" />

Attribute Description
label Friendly name describing what that field contains
length The number of characters to read. Must be a positive integer
id A technical id used to reference in another place the value of the field. (optional) If the id is defined, the referencing syntax is the id between curly brackets. e.g. {pcode}


The const element

This element checks that the next characters are equal to a certain value

example : <const label="Word" value="Hello" />

Attribute Description
label Friendly name describing what that field contains
value The expected value (case-sensitive)


The group element

This element is a container to group a set of other elements

example : <group label="Address">....</group>

Attribute Description
label Friendly name describing what that group represents


The loop element

This element is a container. It defines a repetition of the child elements

example : <loop label="sampleLoop" from="1" to="5" step="1"> ... </loop>

Attribute Description
label Friendly name describing what that loop represents
from start index of the loop. Can be a field reference
to end index of the loop. Can be a field reference
step the step of the loop (optional - default to 1). Can be a field reference


The switch element

This element is a special container. It defines a conditional branching.
This element can only contain one else but multiple case child elements.

example : <switch label="sampleLoop" on="valuetocheck"> ... </switch>

Attribute Description
label Friendly name describing what that switch represents
on define the value that is checked to find the right branching. Can be a field reference


The case element

This element can only be a child of a switch.
This element is a container. It defines a specific branching.

example : <case label="sampleLoop" when="valuetocheck"> ... </case>

Attribute Description
label Friendly name describing what that case represents
when define the value that makes this case the right branching of the parent switch. Can be a field reference


The else element

This element can only be a child of a switch.
This element is a container. It defines a default branching if no specific branching has been found.

example : <else label="sampleLoop"> ... </else>

Attribute Description
label Friendly name describing what that else represents


The partRef element

_example : <partRef label="samplePartRef" partId="part01" />

Attribute Description
label Friendly name describing what that part represents at that specific location
partId The id of the part template defined in the section parts


Last edited Apr 12, 2016 at 10:55 AM by bgiot, version 8