endElement method

void endElement()

Implementation

void endElement() {
  XmlElementBuilder element = _stack.last as XmlElementBuilder;
  if (optimizeNamespaces) {
    // Remove unused namespaces: The reason we first add them and then remove
    // them again is to keep the order in which they have been added.
    element.namespaces.forEach((uri, meta) {
      if (!meta.used) {
        final name = meta.name;
        final attribute = element.attributes.firstWhere(
          (attribute) => attribute.name == name,
        );
        element.attributes.remove(attribute);
      }
    });
  }
  _stack.removeLast();
  _stack.last.children.add(element.build());
}