normalize method

void normalize({
  1. Predicate<XmlText>? collapseWhitespace,
  2. bool? collapseAllWhitespace,
  3. Predicate<XmlText>? normalizeNewline,
  4. bool? normalizeAllNewline,
  5. Predicate<XmlText>? trimWhitespace,
  6. bool? trimAllWhitespace,
})

Puts all child nodes into a "normalized" form, that is

  • combine adjacent text nodes, and
  • remove empty text nodes.

Optionally, the following (possibly destructive) normalization operations can be either performed selectively on text nodes satisfying a predicate, or on all nodes:

  • If the predicate collapseWhitespace is true, consecutive whitespace are replace with a single space-character.
  • If the predicate normalizeNewline is true, line endings are combined according to https://www.w3.org/TR/xml11/#sec-line-ends.
  • If the predicate trimWhitespace is true, leading and trailing whitespace are removed.

Implementation

void normalize({
  // Collapse whitespace:
  Predicate<XmlText>? collapseWhitespace,
  bool? collapseAllWhitespace,
  // Normalize newline:
  Predicate<XmlText>? normalizeNewline,
  bool? normalizeAllNewline,
  // Trim whitespace:
  Predicate<XmlText>? trimWhitespace,
  bool? trimAllWhitespace,
}) =>
    XmlNormalizer(
      collapseWhitespace:
          toPredicate(collapseWhitespace, collapseAllWhitespace),
      normalizeNewline: toPredicate(normalizeNewline, normalizeAllNewline),
      trimWhitespace: toPredicate(trimWhitespace, trimAllWhitespace),
    ).visit(this);