ItunesChannel.fromXml constructor
ItunesChannel.fromXml(
- UniversalFeed rf,
- XmlElement node
Creates a new ItunesChannel from an XmlElement
Implementation
factory ItunesChannel.fromXml(UniversalFeed rf, XmlElement node) {
final nsUrl = rf.meta.extensions.nsUrl(nsItunesNs);
final ic = ItunesChannel._();
getElement<XmlElement>(
node,
'image',
ns: nsUrl,
cb: (value) {
final url = value.getAttribute('href') ?? value.getAttribute('url');
if (url != null) ic.image = Image(url.trim());
},
);
getElement<XmlElement>(
node,
'category',
ns: nsUrl,
cb: (value) {
final cat = value.getAttribute('text')?.trim();
if (cat == null || cat.isEmpty) return;
ic.categories.add(Category(label: cat));
final subCat = value.getElement('category', namespace: nsUrl)?.getAttribute('text')?.trim();
if (subCat != null && subCat.isNotEmpty) ic.categories.add(Category(label: subCat));
},
);
getElement<XmlElement>(
node,
'owner',
ns: nsUrl,
cb: (value) {
ic.owner = Author(
name: value.getElement('name', namespace: nsUrl)?.innerText ?? '',
email: value.getElement('email', namespace: nsUrl)?.innerText ?? '',
);
},
);
ic
..explicit = node.getElement('explicit', namespace: nsUrl)?.innerText.trim()
..author = node.getElement('author', namespace: nsUrl)?.innerText.trim()
..title = node.getElement('title', namespace: nsUrl)?.innerText.trim()
..type = node.getElement('type', namespace: nsUrl)?.innerText.trim()
..newFeedUrl = node.getElement('new-feed-url', namespace: nsUrl)?.innerText.trim()
..block = node.getElement('block', namespace: nsUrl)?.innerText.trim()
..complete = node.getElement('complete', namespace: nsUrl)?.innerText.trim()
..summary = node.getElement('summary', namespace: nsUrl)?.innerText.trim();
getElement<XmlElement>(
node,
'keywords',
ns: nsUrl,
cb: (xml) {
final kws = Set.of(xml.innerText.split(',').map((e) => e.trim())).where((e) => e.isNotEmpty);
if (kws.isEmpty) return;
final cats = List<Category>.generate(
kws.length,
(p) => Category(label: kws.elementAt(p), scheme: 'keyword'),
);
ic.categories.addAll(cats);
},
);
return ic;
}