toXmlString method
String
toXmlString({
- bool pretty = false,
- XmlEntityMapping? entityMapping,
- int? level,
- String? indent,
- String? newLine,
- Predicate<
XmlNode> ? preserveWhitespace, - Predicate<
XmlAttribute> ? indentAttribute, - Comparator<
XmlAttribute> ? sortAttributes, - Predicate<
XmlNode> ? spaceBeforeSelfClose,
inherited
Return an XML string of this object.
If pretty is set to true the output is nicely reformatted, otherwise
the tree is emitted verbatim.
The entityMapping defines how character entities are encoded into the
resulting output.
The remaining options are used for pretty printing only:
- The option
indentdefines the indention of nodes, by default nodes are indented with 2 spaces. - The option
newLinedefines the printing of new lines, by default the standard new-line'\n'character is used. - The option
levelcustomizes the initial indention level, by default this is0. - If the predicate
preserveWhitespacereturnstrue, the whitespace characters within the node and its children are preserved by switching to non-pretty mode. By default all whitespace is normalized. - If the predicate
indentAttributereturnstrue, the attribute will be begin on a new line. Has no effect within elements where whitespace are preserved. - If the
sortAttributesis provided, attributes are on-the-fly sorted using the provided Comparator. - If the predicate
spaceBeforeSelfClosereturnstrue, self-closing elements will be closed with a space before the slash (<example />).
Implementation
String toXmlString({
bool pretty = false,
XmlEntityMapping? entityMapping,
int? level,
String? indent,
String? newLine,
Predicate<XmlNode>? preserveWhitespace,
Predicate<XmlAttribute>? indentAttribute,
Comparator<XmlAttribute>? sortAttributes,
Predicate<XmlNode>? spaceBeforeSelfClose,
}) {
final buffer = StringBuffer();
final writer = pretty
? XmlPrettyWriter(
buffer,
entityMapping: entityMapping,
level: level,
indent: indent,
newLine: newLine,
preserveWhitespace: preserveWhitespace,
indentAttribute: indentAttribute,
sortAttributes: sortAttributes,
spaceBeforeSelfClose: spaceBeforeSelfClose,
)
: XmlWriter(buffer, entityMapping: entityMapping);
writer.visit(this);
return buffer.toString();
}