from static method

XmlAttribute? from(
  1. String string, {
  2. bool parseCharacterEntities = true,
})

Returns the first attribute found in string. string must not be null.

If parseCharacterEntities is true, attribute values will be parsed and replace all encoded character entities with their corresponding character. parseCharacterEntities must not be null.

Returns null if no attributes are found.

Implementation

static XmlAttribute? from(
  String string, {
  bool parseCharacterEntities = true,
}) {
  string = string.removeComments();
  final attribute = Delimiters.attribute.firstMatch(string);
  if (attribute == null) return null;
  final name = attribute.namedGroup('name');
  var value = attribute.namedGroup('value');
  if (parseCharacterEntities) value = HtmlCharacterEntities.decode(value!);
  return XmlAttribute(name!, value!);
}