setAttribute static method

void setAttribute(
  1. XmlElement node,
  2. String tag,
  3. String? value
)

Changes an XmlElement attribute value

Implementation

static void setAttribute(XmlElement node, String tag, String? value) {
  try {
    value ??= "";
    value.replaceAll('"', """);
    value.replaceAll("'", """);

    XmlAttribute? a = node.getAttributeNode(tag);
    if (a == null) {
      node.attributes.add(XmlAttribute(XmlName(tag), value));
    } else {
      a.value = value;
    }
  } catch (e) {
    Log().exception(e,
        caller:
            'xml.dart => String attribute({XmlElement node, String tag})');
  }
}