toXMLString method
Implementation
String toXMLString([int indentLevel = 0]) {
final indent = ' ' * indentLevel;
final attributesString =
attributes.entries.map((e) => '${e.key}="${e.value}"').join(' ');
final xmlHeader =
indentLevel == 0 ? '<?xml version="1.0" encoding="UTF-8"?>\n' : '';
final attributesPart =
attributesString.isNotEmpty ? ' $attributesString' : '';
if (body == null) {
return '$xmlHeader$indent<$tag$attributesPart/>';
} else if (body is XMLValue) {
return '$xmlHeader$indent<$tag$attributesPart>${(body as XMLValue).body}</$tag>';
} else if (body is XMLChildren) {
final children = (body as XMLChildren)
.body
.map((child) => child.toXMLString(indentLevel + 1))
.join('\n');
return '''$xmlHeader$indent<$tag$attributesPart>
$children
$indent</$tag>''';
}
return '';
}