setTagFrom<T extends TagXml> method

T? setTagFrom<T extends TagXml>(
  1. String childName,
  2. T? value
)

Sets a child node with the given childName to the provided value.

If the value is not null, it adds the value's as child. If the value is null, it removes the child node if it exists.

Implementation

T? setTagFrom<T extends TagXml>(String childName, T? value) {
  var n = findElements(childName).singleOrNull;
  if (n != null) {
    n.remove();
  }
  if (value != null) {
    if (value.hasParent) value.remove();
    children.add(value);
    value.tagName = childName;
  }
  return value;
}