CustomNamespace.parse constructor

CustomNamespace.parse(
  1. XmlElement element
)

Factory method to create a CustomNamespace object from an XmlElement.

This method parses the element and extracts its descendant elements to create a map of custom tags. It then uses this map to initialize a CustomNamespace object and returns it.

Implementation

factory CustomNamespace.parse(XmlElement element) {
  final customTags = <String, dynamic>{};

  // Loop through all the descendant elements of the given [element].
  element.descendantElements.forEach((descendantElement) {
    // Add the name and inner text of each descendant element to the customTags map.
    customTags.addEntries([
      MapEntry(
        descendantElement.name.toString(),
        descendantElement.innerText,
      ),
    ]);
  });

  return CustomNamespace(customTags: customTags);
}