Skip to content

Automatic trimming? #120

Answered by renggli
tiloc asked this question in Q&A
Discussion options

You must be logged in to vote

You can easily do that as part of a transformation step after parsing:

final document = XmlDocument.parse(input);

// Trim all the text nodes
for (final node in document.descendants.whereType<XmlText>()) {
  node.replace(XmlText(node.text.trim()));
}

Possibly you also want to normalize the document afterwards (remove empty text nodes):

document.normalize();

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by renggli
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #99 on December 29, 2021 11:10.