attribute method
void
attribute(
- String name,
- Object? value, {
- String? namespaceUri,
- String? namespacePrefix,
- XmlAttributeType? attributeType,
- @Deprecated('Use `namespaceUri` instead') String? namespace,
Adds a XmlAttribute node with the provided name and value.
For the namespace either a previously defined namespacePrefix or
namespaceUri can be provided, but not both.
To generate an element with the tag message and the attribute lang="en" one would write:
builder.element('message', nest: () {
builder.attribute('lang', 'en');
});
Implementation
void attribute(
String name,
Object? value, {
String? namespaceUri,
String? namespacePrefix,
XmlAttributeType? attributeType,
@Deprecated('Use `namespaceUri` instead') String? namespace,
}) {
final attributeName = _buildName(
name,
prefix: namespacePrefix,
uri: namespaceUri ?? namespace,
);
final attributeNode = XmlAttribute(
attributeName,
value.toString(),
attributeType ?? XmlAttributeType.DOUBLE_QUOTE,
);
final attributes = _nodes.last.attributes;
if (value != null) {
attributes[attributeName.qualified] = attributeNode;
} else {
attributes.remove(attributeName.qualified);
}
}