The Optional property specifies how delimiters for optional nodes are to be handled when the nodes are absent from the input instance or when their fields are empty.
Table 11 Optional Mode Options
Option |
Rule |
---|---|
never |
If the node is absent, the delimiter is not allowed in either input or output. |
allow |
If the node is absent, the delimiter is allowed in input but will not be emitted in output. |
cheer |
If the node is absent, the delimiter is allowed in input and will also be emitted in output. |
force |
If the node is absent, the delimiter must appear in input and will be emitted in output. Note – Only this option allows trailing delimiters for a sequence of absent optional nodes. |
As illustrative examples, consider the tree structures shown in the following figure and table, where the node a has a caret (^) as its delimiter, and the child nodes b, c, and d all have asterisks (*) as their delimiters.
Example 1: Child node c is optional. (Child nodes c and d must have different values for the match parameter.)
Option |
Input |
Output |
---|---|---|
never |
b*d^ |
b*d^ |
allow |
b**d^ |
b*d^ |
cheer |
b**d^ |
b**d^ |
force |
b**d^ |
b**d^ |
Example 2: Child nodes c and d are both optional.
Option |
Input |
Output |
---|---|---|
never |
b^ |
b^ |
allow |
b^, b*^, or b**^ |
b^ |
cheer |
b^, b*^, or b**^ |
b**^ |
force |
b**^ |
b**^ |