The <record> element is used to group one or more elements together. By default, the record's children have their own scope.
| Attributes |
|
%record elements provide a way to group several elements together. the <record> can then be used in expressions as a single element.
We can use the import attribute to import the children of the <record>
into the same scope as the <record> element itself. This way, subsequent
expressions can reference named elements in the <record>.
The following example divides a message into two sections, a header and a
body (similar to IP). Since the header record is imported, the Data
field in the body can reference it.
<xddl>
<structure>
<record name="Header" import="true">
<field name="Length" length="8"/>
</record>
<record name="Body">
<field name="Data" length="8 * Length"/>
</record>
</structure>
</xddl>
import.xddl
If we did not import the header, the Length reference in the Data
field would cause an error when the file is loaded.
We can restrict the length of a record with the length attribute. The
length will be force to be this value even if the lengths of the child
elements are not the same.
This can be used for frame-based messages or for forward compatibility.