visitElement method

  1. @override
void visitElement(
  1. XmlElement node
)
override

Visit an XmlElement node.

Implementation

@override
void visitElement(XmlElement node) {
  buffer.write(XmlToken.openElement);
  visit(node.name);
  writeAttributes(node);
  if (node.children.isEmpty && node.isSelfClosing) {
    buffer.write(XmlToken.closeEndElement);
  } else {
    buffer.write(XmlToken.closeElement);
    if (node.children.isNotEmpty) {
      if (pretty) {
        if (preserveWhitespace != null && preserveWhitespace(node)) {
          pretty = false;
          writeIterable(node.children);
          pretty = true;
        } else if (node.children.every((each) => each is XmlText)) {
          writeIterable(normalizeText(node.children));
        } else {
          level++;
          buffer.write(newLine);
          buffer.write(indent * level);
          writeIterable(
              normalizeText(node.children), newLine + indent * level);
          level--;
          buffer.write(newLine);
          buffer.write(indent * level);
        }
      } else {
        writeIterable(node.children);
      }
    }
    buffer.write(XmlToken.openEndElement);
    visit(node.name);
    buffer.write(XmlToken.closeElement);
  }
}