text method
Adds a XmlText
node with the provided text
.
For example, to generate the text Hello World one would write:
builder.text('Hello World');
Implementation
void text(Object? text) {
final children = _stack.last.children;
if (children.isNotEmpty && children.last is XmlText) {
// Merge consecutive text nodes into one
final previous = children.removeLast();
children.add(XmlText('${previous.text}${text.toString()}'));
} else {
children.add(XmlText(text.toString()));
}
}