Native Data DOM XML

Unit: HPDFXFARuntime

Methods

dataNode.loadXML(xml, ignoreRoot = true, overwrite = false);
const compact = dataNode.saveXML();
const readable = dataNode.saveXML("pretty");

These script methods are available on datasets, dataGroup and dataValue nodes in TXFAWidgetRuntime events

saveXML returns UTF-8 XML with a declaration and the selected node as its document element; the optional pretty argument adds indentation to element-only content

loadXML accepts one well-formed XML document; ignoreRoot imports its children into the selected node, while False imports the source document element as a child

overwrite removes existing target content before importing; its default False appends content and preserves existing child identities

The selected node retains its identity and attributes; imported child attributes and their namespace mappings are preserved

Immediate graph and bindings

const record = xfa.datasets.data.main;
record.loadXML("<main><amount>42</amount></main>", true, true);
const amount = record.amount;
amount.value = "43";
if (this.parent.amount.rawValue !== "43") throw new Error("Missing binding update");

A successful native parse immediately installs the imported children in the current script graph; ordinary properties and SOM selectors resolve those fresh nodes before event publication

Data cells synchronise with bound field aliases in both directions, including hidden fields, newly supplied binding targets and existing descendant, wildcard, class and numeric-index dataRef selectors

Scalar-to-group imports update the target's data class and expose its imported child elements; an emptied dataValue has an empty string value

Importing a new data element does not allocate unrelated ambiguous data leaves for unresolved bindings

Identity and repeated scopes

Mixed content and retained identities

Appending XML keeps existing named elements and already materialised unnamed character values as separate logical children in document order, including during an import on their parent

For <mixed>left<b>inner</b>right</mixed>, appending <incoming><c>more</c></incoming> with ignoreRoot=true and overwrite=false preserves the original left, b and right objects and adds c after them

Comments, processing instructions and CDATA remain in their original XML positions; when adjacent ordinary text combines during import, the retained character value reflects the combined text

Overwrite invalidates previous named and character child handles and publishes new children; character values do not change the native addressing of named imported elements

Version 2.1160.0 persists direct rawValue and value writes to newly imported unnamed character values, including through a bound field's dataNode; the script graph, native dataset and enclosing aggregate fields stay synchronised

Appending adjacent ordinary text combines it with the existing trailing text record and retains that record's identity; CDATA, comments, processing instructions and element boundaries remain distinct, so later character writes reach the same native target

See character-value editing for empty values, saved XML, resource limits and the supported write surface

Overwrite invalidates old child handles and publishes fresh child identities; a script object can retain a fresh imported data handle and use it in subsequent events

Appending preserves existing handles; importing inside a repeated row changes that row's native data scope and bound fields

XML imports also work inside an occurrence created by addInstance during the same event

Replacing the datasets content updates $data and $record to the new native roots, and rebases surviving form and script-object identities so lexical module state remains attached to its form scope

Accepted scope migration

Successful native overwrites migrate cached scalar and group bindings using the old-to-replacement mappings accepted for that import. A following field write reaches the replacement data leaf, including a selected repeated row and hidden aliases, while surviving Form and script-object scopes retain their lexical state

Removed data-node handles retain their retirement behaviour. A missing replacement does not revive a removed identity through unrestricted same-path lookup, and an explicitly selected missing record is not redirected to a new record at the same ordinal

Detached Data DOM trees retain their existing cross-event XML operations. Saved values and accepted module state participate in the surrounding native import transaction and its rollback

Content and persistence

Native imports and saved XDP preserve ordinary text, CDATA, comments and processing instructions in order

Comments and processing instructions remain outside ordinary Data DOM element selection and do not become visible field text

Imported nodes preserve their namespace URI even beneath a different ancestor default namespace, including the explicit empty default namespace for no-namespace elements

Foreign prefixed attributes retain expanded names, and Unicode local names, accented text and supplementary characters survive native save and reload

Read-only saveXML does not materialise form properties or change saved XDP bytes

Validation and rollback

The native XML parser checks well-formedness, namespace and attribute validity, XML characters, declaration placement and entity syntax before graph mutation

Malformed input can be caught in JavaScript; the previous native and script graph remains available, and a later valid mutation can still commit

A failed event restores the document bytes, widget values, imported graph, identities and script-object lexical state, including failures after the native XML import has already been applied

Each native JavaScript session retains its actual DLL module while rebuilding engines for response replay; engines, contexts and journals remain independent, and the module reference is released after the final native engine teardown

XML parsing and serialisation enforce operation, depth, node, byte and elapsed-time budgets together with the runtime's original event deadline and value-character limits

Version 2.1153.1 applies MaxValueChars to Form-structure raw-value actions after a Data XML import, using the same UTF-16 code-unit boundary as ordinary raw-value writes. Values at the limit remain accepted; oversized writes fail before native mutation and restore the complete event transaction

Imports do not resolve external entities or perform file, network or UI actions; DTD declarations are rejected by this parser

Current scope

The shared native XML event path has recorded Delphi Win64 and Linux x64 acceptance. The Version 2.1154.0 Linux record (Tests/XFA/DataXMLPortable/Acceptance-2.1154.0.json) covers FPC 3.3.1 build 3.3.1-20818-ga205e76e12-dirty on one WSL2 host: 141 Data XML checks, 17 migration checks and 21 saved XML parses. This does not imply other compiler builds, hosts or architectures have been tested

Data node creation, cloning, renaming and reparenting are available through transactional Data DOM structure. Record-window navigation and supported record-mode global bindings have their own runtime APIs and limits

Live script SOM paths support predicates. General predicates in native bind.dataRef paths and dedicated script setters for arbitrary Data DOM attributes remain outside the XML method surface

Related APIs

Native Data DOM, Native Bind SOM, TXFAEventBinding, TXFAEventAction and Interactive XFA Runtime

Attribute-backed metadata and semantic properties

Version 2.1155.9 adds attribute-backed Data metadata: attributes on a saved Data element materialise as DataValue children of an owner element, preserving document order, cloning, retirement and exact rollback. Data values expose semantic value, contentType and isNull reads; MIME conversion keeps hidden rich content, explicit empty values and nil-excluded raw text out of the current value while save and reload reproduce them. Scripts can call getAttribute and setAttribute on ordinary Data nodes inside the normal event transaction, and previously accepted references survive later Data edits, failed transactions and document reload

Semantic verdicts cache per node and invalidate at each mutation point, so the full property-write transaction completes within the default script operation budget