parse method

Future<FormDef> parse(
  1. String formXml, {
  2. String? formXmlSrc,
  3. String? lastSavedSrc,
  4. String? instanceXml,
  5. AnswerResolver answerResolver = defaultAnswerResolver,
  6. bool restoringCachedForm = false,
})

Parses formXml. lastSavedSrc is the src to use for jr://instance/last-saved. With instanceXml (a saved instance), its answers replace the blank instance (typed by answerResolver).

restoringCachedForm re-parses a form that parsed before (see FormDefCodec) the way JavaRosa's readExternal restores one: a missing external secondary instance file throws ResourceNotFoundException instead of being replaced by a placeholder, and itemset label and value nodes in external instances are not verified (deserialization does no parse-time verification).

Implementation

Future<FormDef> parse(
  String formXml, {
  String? formXmlSrc,
  String? lastSavedSrc,
  String? instanceXml,
  AnswerResolver answerResolver = defaultAnswerResolver,
  bool restoringCachedForm = false,
}) async {
  final root = getXmlDocument(formXml);
  await _parseDoc(
    root,
    formXmlSrc,
    lastSavedSrc,
    restoringCachedForm: restoringCachedForm,
  );
  _f
    ..sourceXml = formXml
    ..lastSavedSrc = lastSavedSrc;
  if (instanceXml != null) {
    _f.loadXmlInstance(instanceXml, resolver: answerResolver);
  }
  for (final processor in _formDefProcessors) {
    processor.processFormDef(_f);
  }
  return _f;
}