appendJson method

MeshElement appendJson(
  1. Map<String, dynamic> json
)

Implementation

MeshElement appendJson(Map<String, dynamic> json) {
  final tagName = tagNameFromJson(json);
  final attributes = attributesFromJson(json);
  final elementType = doc.schema.element(tagName);

  if (elementType.childPropertyName != null) {
    final element = createChildElement(tagName, attributes);

    if (attributes.containsKey(elementType.childPropertyName!)) {
      // Extract children
      final children = attributes.remove(elementType.childPropertyName!) as List;
      // Create the element

      // Append each child
      for (final child in children) {
        element.appendJson(child as Map<String, dynamic>);
      }
    }
    return element;
  } else {
    // Just create the child element with given attributes
    return createChildElement(tagName, attributes);
  }
}