Content.parse constructor
Content.parse(
- XmlElement element
Factory method to create a new Content instance from an XML element.
The factory constructor takes an XmlElement representing the "media:content" element
and extracts its attributes 'url', 'type', 'fileSize', 'medium', 'isDefault', 'expression',
'bitrate', 'framerate', 'samplingrate', 'channels', 'duration', 'height', and 'width'.
It uses int.tryParse and double.tryParse methods to parse numeric attributes and initializes
the properties of the Content object with these values. The 'isDefault' attribute is parsed
as a boolean.
Implementation
factory Content.parse(XmlElement element) {
return Content(
url: element.getAttribute('url'), // Extract the 'url' attribute.
type: element.getAttribute('type'), // Extract the 'type' attribute.
fileSize: int.tryParse(element.getAttribute('fileSize') ??
'0'), // Extract and parse 'fileSize' attribute.
medium: element.getAttribute('medium'), // Extract the 'medium' attribute.
isDefault: element.getAttribute('isDefault') ==
'true', // Parse 'isDefault' attribute as a boolean.
expression: element
.getAttribute('expression'), // Extract the 'expression' attribute.
bitrate: int.tryParse(element.getAttribute('bitrate') ??
'0'), // Extract and parse 'bitrate' attribute.
framerate: double.tryParse(element.getAttribute('framerate') ??
'0'), // Extract and parse 'framerate' attribute.
samplingrate: double.tryParse(element.getAttribute('samplingrate') ??
'0'), // Extract and parse 'samplingrate' attribute.
channels: int.tryParse(element.getAttribute('channels') ??
'0'), // Extract and parse 'channels' attribute.
duration: int.tryParse(element.getAttribute('duration') ??
'0'), // Extract and parse 'duration' attribute.
height: int.tryParse(element.getAttribute('height') ??
'0'), // Extract and parse 'height' attribute.
width: int.tryParse(element.getAttribute('width') ??
'0'), // Extract and parse 'width' attribute.
lang: element.getAttribute('lang'), // Extract the 'lang' attribute.
);
}