-
I am parsing XML with lots of text nodes. It is split out into multiple lines. Like Now when I access the .text property of a node to get the text it comes with a lot of leading and trailing line breaks and tabs. Of course I can call trim() on each and every one, but could the parser get an option to automatically return trimmed text? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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(); |
Beta Was this translation helpful? Give feedback.
-
Thanks! That works great for me! |
Beta Was this translation helpful? Give feedback.
You can easily do that as part of a transformation step after parsing:
Possibly you also want to normalize the document afterwards (remove empty text nodes):
document.normalize();