Re: XForms 2.0 proposal: Schema-derived node construction for insert

Dear Ivan,


Thank you for your suggestion, which we discussed today.


Our thoughts on this are that this is really something that ought to be suggested to the XPath 4.0 group. Their current spec is at
https://qt4cg.org/specifications/xpath-functions-40/Overview.html
They meet weekly on Mondays.


However, we strongly urge you to consider creating such a function, in order to experiment with it, and report back to us your experience for later adoption.


Best wishes,


Steven



We are implementing XForms 2.0 and would like to propose an additional capability for constructing instance nodes based on XML Schema declarations.

This is a feature proposal rather than a question about the interpretation of existing requirements.

 

Current capabilities

XForms 2.0 already provides several mechanisms for supplying nodes to the “insert”  action:

 

- Using the default  “origin”, which copies the last item of the destination sequence.

- Copying an existing node from the same or another instance, often maintained as a prototype.

- Constructing nodes explicitly using functions such as xf:element() and xf:attribute() .

- Parsing an XML string using xf:parse()

 

These mechanisms allow authors to construct arbitrary XML structures. However, they require the author to explicitly provide the structure of the node being inserted.

When an XML Schema already defines that structure, the same information must effectively be maintained in two places: the schema and the XForms expression or prototype.

If the schema changes, the construction logic may become outdated without any immediate indication.

Example: Inserting into an empty collection

 

Consider the following XML Schema declaration:

 

<xs:element name="people">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="person"

                  minOccurs="0"

                  maxOccurs="unbounded">

        <xs:complexType>

          <xs:sequence>

            <xs:element name="firstName"

                        type="xs:string"/>

            <xs:element name="lastName"

                        type="xs:string"/>

          </xs:sequence>

        </xs:complexType>

      </xs:element>

    </xs:sequence>

  </xs:complexType>

</xs:element>

 

 

An XForms application may initially contain:

 

<xf:instance id="main">

  <people/>

</xf:instance>

 

 

This initial instance is schema-valid because the “person” element is optional. The author is not recovering from a validation error; the application simply needs to create the first item in the collection.

 

The specification states that an  “insert”  action has no effect if:

 

"the source sequence is empty (which includes the destination sequence being empty, with no non-default source sequence)"

 

It also states that each item is inserted:

 

"next to the destination location, if the destination sequence is non-empty, into the context node otherwise, ignoring at and position"

 

Thus, inserting into an empty collection is already supported, provided that the author supplies a source node.

 

The author can maintain a prototype or explicitly construct the structure:

 

 

<xf:insert

    context="instance('main')/people"

    ref="person"

    origin="xf:element('person', (

        xf:element('firstName'),

        xf:element('lastName')

    ))"/>

 

 

However, this duplicates the structural information already present in the XML Schema.

If a required child is added to the schema, the construction expression must also be updated manually.

 

Proposed capability

 

We would like to suggest a mechanism for constructing an element based on its applicable XML Schema declaration.

Conceptually, this could be exposed as a function usable within the existing  “insert”  action, for example:

 

<xf:insert

    context="instance('main')/people"

    ref="person"

    origin="xf:element-from-schema(

        instance('main')/people,

        'person'

    )"/>

 

 

The function name and signature are illustrative only 😊

 

The intended behavior would be to construct a new  “person”  element, including the required structural components defined by the applicable XML Schema, without requiring the author to maintain a separate prototype or duplicate the schema structure in an XPath expression.

 

Because  “origin”  already accepts an expression, such a function would require no change to the “insert”  action itself.

 

We recognize that XML Schema does not always determine a unique instance structure, and that several design questions would need to be addressed:

 

-  Optional content:  Should elements with  minOccurs="0"  be omitted by default?

- Choices:  How should a branch of an  xs:choice  be selected, and should the author be able to specify the desired branch?

- Attributes:  Should attributes declared with  use="required"  be constructed as well, and with which value when the schema does not provide one?

- Values:  Should the mechanism construct only the required structure, leaving values empty where possible, rather than attempting to generate a fully schema-valid instance?

-  Schema context:  How should the applicable declaration be identified when multiple local declarations with the same element name exist in different content models?

- Target context:  Should schema-derived node construction explicitly receive the intended parent node and child name, or should the processor derive the applicable schema declaration from the destination context of the  “insert” action?

 

Our primary motivation is to avoid duplicating schema-defined structures in XForms applications and to make node construction more resilient to schema evolution.

 

The XForms processor is already required to process the XML Schemas referenced by the model. The proposed capability would make use of schema information involved in that processing, rather than requiring authors to provide a separate structural definition.

 

We would be interested to hear whether such a capability has been considered for XForms 2.0, and whether a schema-aware node construction function would fit within the existing design.

 

Thank you for your consideration.

 

Best regards,

 

 

 

 

 

Mgr. Ivan Turčan




Senior Software Engineer




 




DRAKE Solutions s.r.o.




Na Troskách 26




974 01 Banská Bystrica, Slovensko




 




M   +421 905 500 958 <tel:+421905500958>




E   ivan.turcan@drake.sk <mailto:ivan.turcan@drake.sk>




W   www.drake.sk <https://www.drake.sk/>




 




 




 




Sídlo spoločnosti: Borovicová 6686/27, 974 05 Banská Bystrica, Slovensko




IČO: 47868244   |   IČ DPH: SK2024122320

Received on Friday, 23 October 2026 14:51:42 UTC