normalize method
void
normalize({})
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
istrue
, consecutive whitespace are replace with a single space-character. - If the predicate
normalizeNewline
istrue
, line endings are combined according to https://www.w3.org/TR/xml11/#sec-line-ends. - If the predicate
trimWhitespace
istrue
, 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);