You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何获取XML内itunes:image标签的href链接以生成缩略图

从带前缀的XML标签中提取href属性生成缩略图

问题场景

尝试从XML文件里的带前缀标签(如<something:another_thing>)中提取href属性链接来生成缩略图,过程中遇到瓶颈,最终找到了解决方案。

原代码

list() {
 return ListView.builder(
  itemCount: _feed.items?.length,
  itemBuilder: (BuildContext context, int index) {
    final item = _feed.items![index];
    return ListTile(
      title: title(item.title),
      subtitle: subtitle(item.pubDate),

      leading: thumbnail(item.itunes.image),
      trailing: rightIcon(),
      contentPadding: EdgeInsets.all(5.0),
      //onTap: () => openFeed(item.link),
    );
  },
);
}

对应XML标签

<itunes:image href="link"/>

核心疑问

  • 如何获取itunes:image标签
  • 如何获取该标签的href内容

解决方案

通过链式调用解析后的模型属性,直接获取href值:

leading: thumbnail(item.itunes!.image!.href)

解析后的实体类中,item对象的itunes字段包含image子对象,而image对象已映射XML标签的href属性,因此可以通过上述链式调用拿到缩略图链接。

内容的提问来源于stack exchange,提问作者Toxic Axes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 17:18:25