Embed.parse constructor

Embed.parse(
  1. XmlElement element
)

Factory method to create a new Embed instance from an XML element.

The factory constructor takes an XmlElement representing the "embed" element and extracts its attributes 'url', 'width', and 'height', as well as any child "media:param" elements. It uses these values to initialize the properties of the Embed object.

Implementation

factory Embed.parse(XmlElement element) {
  return Embed(
    url: element.getAttribute('url'), // Extract the 'url' attribute.
    width: int.tryParse(element.getAttribute('width') ??
        '0'), // Extract the 'width' attribute.
    height: int.tryParse(element.getAttribute('height') ??
        '0'), // Extract the 'height' attribute.
    params: element
        .findElements('media:param') // Find all child "media:param" elements.
        .map((e) =>
            Param.parse(e)) // Convert each child element to a Param object.
        .toList(), // Convert the iterable to a list.
  );
}