loadXmlInstance method
Replaces the main instance with the saved instance instanceXml
(typed against the form). Port of XFormParser.loadXmlInstance.
Implementation
void loadXmlInstance(
String instanceXml, {
AnswerResolver resolver = defaultAnswerResolver,
}) {
final savedRoot = restoreDataModel(getXmlDocument(instanceXml)).root;
final templateRoot = mainInstance.root.deepCopy(includeTemplates: true);
// A weak check that the instance belongs to the form.
if (savedRoot.name != templateRoot.name || savedRoot.multiplicity != 0) {
throw StateError(
'Saved form instance does not match template form definition',
);
}
templateRoot.populate(savedRoot, this, resolver: resolver);
mainInstance.setRoot(templateRoot);
}