setDocStringValue method

void setDocStringValue({
  1. required XmlDocument doc,
  2. required String name,
  3. required String attributeName,
  4. required String targetKey,
  5. required String targetValue,
  6. bool autoFill = false,
})

Implementation

void setDocStringValue({
  required XmlDocument doc,
  required String name,
  required String attributeName,
  required String targetKey,
  required String targetValue,
  bool autoFill = false,
}) {
  List<XmlElement> list = doc.findAllElements(name).toList();
  final targetElements = list.where((e) => e.getAttribute(attributeName) == targetKey).toList();
  if (targetElements.isEmpty) {
    if (autoFill) {
      final newElement = XmlElement(XmlName.fromString(name));
      newElement.setAttribute(attributeName, targetKey);
      newElement.innerText = targetValue;
      list.first.parent?.children.add(newElement);
    }
  } else {
    for (XmlElement e in targetElements) {
      e.innerText = targetValue;
    }
  }
}