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 && attributes.containsKey(elementType.childPropertyName!)) {
    // Extract children
    final children = attributes.remove(elementType.childPropertyName!) as List;
    // Create the element
    final element = createChildElement(tagName, attributes);
    // 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);
  }
}