private static Element withValueOrContent(String name, String value) {
    Element element = new Element(name);
    if (!value.isEmpty() && (Character.isWhitespace(value.charAt(0)) || Character.isWhitespace(value.charAt(value.length() - 1)))) {
      return element.setAttribute("value", value);
    }
    return element.setText(value);
  }
private static Element withValueOrContent(String name, String value)