Obtains the value of a field of the struct.

1 struct.get

Allows to create a struct.

<struct.get field='field'>
    <var /> !
</struct.get>

Exceptions

attribute 'field' required

The field name has not been specified.

undefined field [...] on struct [...]

The indicated field does not exist in the struct.

requires 1 arguments, received [...]

The correct number of arguments has not been informed.

struct.get: bad type - expected [StructInstance] while found [...]

The variable specified as argument is not of struct type.

Example

Obtain the values of a variable of struct type, through <struct.get>

Copy
<xsql-script name='struct_get_sample1'>
    <body>
        <struct.declare type='point2d'>
            <field name='x' type='double' />
            <field name='y' type='double' />
        </struct.declare>
        <set name='m_point'>
            <struct type='point2d'>
                <number>10</number>
                <number>20</number>
            </struct>
        </set>
        <println>X=<struct.get field='x'><m_point/></struct.get></println>
        <println>Y=<struct.get field='y'><m_point/></struct.get></println>
    </body>
</xsql-script>

Screen printing would be the following:

X=10.0

Y=20.0

Example

Obtains the values of a variable of struct type, without using <struct.get>:

Copy
<xsql-script name='struct_get_sample2'>
    <body>
        <struct.declare type='point3d'>
            <field name='x' type='integer' />
            <field name='y' type='integer' />
            <field name='z' type='integer' />
        </struct.declare>
        <set name='m_point'>
            <struct type='point3d'>
                <number>2</number>
                <number>4</number>
                <number>6</number>
            </struct>
        </set>
        <println>X=<m_point.x/></println>
        <println>Y=<m_point.y/></println>
        <println>Z=<m_point.z/></println>
    </body>
</xsql-script>

Unlike the previous example, the value of the struct field is obtained, making reference to the content through the concatenation of the name of the variable ('m_point'), the character '.' (point) and the field name ('x').

The result by console would be the following:

X=2

Y=4

Z=6