Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
flatter中图像的Xml解析_Xml_Parsing_Flutter_Rss_Cdata - Fatal编程技术网

flatter中图像的Xml解析

flatter中图像的Xml解析,xml,parsing,flutter,rss,cdata,Xml,Parsing,Flutter,Rss,Cdata,我想解析一个图像并在应用程序中使用它。但我真正需要的是图像标记中的src链接,以及linik标记中的CDATA 这是rss源: <rss version="2.0"> <channel> <title>E! Online (US) - Top Stories</title> <link>https://www.eonline.com/</link> <category>(US) - Top Stories<

我想解析一个图像并在应用程序中使用它。但我真正需要的是图像标记中的src链接,以及linik标记中的CDATA

这是rss源:

<rss version="2.0">
<channel>
<title>E! Online (US) - Top Stories</title>
<link>https://www.eonline.com/</link>
<category>(US) - Top Stories</category>
<description>
News from across the show-biz spectrum-TV, movies, music and celebrities
</description>
<language>en-us</language>
<ttl>10</ttl>
<pubDate>Mon, 13 Apr 2020 00:42:22 GMT</pubDate>
<lastBuildDate>Mon, 13 Apr 2020 00:42:22 GMT</lastBuildDate>
<image>
<title>E! Online (US) - Top Stories</title>
<width>120</width>
<height>60</height>
<link>https://www.eonline.com/</link>
<url>
https://images.eonline.com/eol_images/Entire_Site/2018223/rs_125x40-180323122205-EGoogleNews.png
</url>
</image>
<copyright>
© 2020 E! Entertainment Television, Inc. All rights reserved., https://www.eonline.com/about/copyright/index.jsp
</copyright>
<item>
<title>
Jennifer Lopez and Diddy Reunite on Instagram Live During His Dance-a-Thon Fundraiser
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1140003/jennifer-lopez-and-diddy-reunite-on-instagram-live-during-his-dance-a-thon-fundraiser?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/201742//rs_600x600-170502090801-600-jennifer-lopez-diddy-met-gala-alex-rodriguez.jpg" height="66" width="66" border="0" alt="Jennifer Lopez, Sean Diddy Combs, MET Gala Then and Now" align="left" hspace="5" />Who's got better dance moves: Jennifer Lopez or Sean "Diddy" Combs? On Sunday, Diddy asked his fellow celeb friends to get up and dance for a cause. Posting on Instagram,...<br clear="all" />
</description>
<pubDate>Mon, 13 Apr 2020 00:42:22 GMT</pubDate>
<guid isPermaLink="false">b1140003</guid>
</item>
<item>
<title>
Tiger King Aftershow Episode: 5 of the Biggest Bombshells
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1139997/tiger-king-aftershow-episode-5-of-the-biggest-bombshells?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/2020230//rs_600x600-200330065841-600-5-tiger-king-ch-033020.jpg" height="66" width="66" border="0" alt="Tiger King" align="left" hspace="5" />Hey all you cool cats and kittens... Netflix is giving the fans what they want: another Tiger King episode. That's right, the streaming service knew people were craving more...<br clear="all" />
</description>
<pubDate>Mon, 13 Apr 2020 00:04:21 GMT</pubDate>
<guid isPermaLink="false">b1139997</guid>
</item>
<item>
<title>
Mariah Carey Blesses Us on Easter With Virtual Performances of Her Emancipation of Mimi Singles
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1139991/mariah-carey-blesses-us-on-easter-with-virtual-performances-of-her-emancipation-of-mimi-singles?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/2020312//rs_600x600-200412134740-600_Mariah_Carey_MP_4.12.20.jpg" height="66" width="66" border="0" alt="Mariah Carey, Instagram" align="left" hspace="5" />Mariah Carey is not only celebrating Easter Sunday this weekend but she's also celebrating the 15th anniversary of one of her most iconic albums, The Emancipation of Mimi. The...<br clear="all" />
</description>
<pubDate>Sun, 12 Apr 2020 22:27:45 GMT</pubDate>
<guid isPermaLink="false">b1139991</guid>
</item>
<item>
<title>
Hilary Duff Says Goodbye to Her Blonde Hair and Reveals an Epic New Look
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1139985/hilary-duff-says-goodbye-to-her-blonde-hair-and-reveals-an-epic-new-look?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/2019913//rs_600x600-191013094707-600-hilary-duff.cm.101319.jpg" height="66" width="66" border="0" alt="Hilary Duff" align="left" hspace="5" />Hilary Duff's blonde hair is "so yesterday." The 32-year-old star is celebrating Easter 2020 with a new hairstyle and hair color. On Sunday afternoon, the Lizzie...<br clear="all" />
</description>
<pubDate>Sun, 12 Apr 2020 22:23:26 GMT</pubDate>
<guid isPermaLink="false">b1139985</guid>
</item>
<item>
<title>
The Disney Music Playlist You Need to Boost Your Mood Right Now
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1138074/the-disney-music-playlist-you-need-to-boost-your-mood-right-now?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/202036//rs_600x600-200406183221-600.disney_playlist_e.gif" height="66" width="66" border="0" alt="Disney Song Playlist" align="left" hspace="5" />Get ready to start smiling! It's been 25 years since Disney released A Goofy Movie on April 7, 1995, spinning off the classic anthropomorphic dog Goofy and his teenage son Max Goof...<br clear="all" />
</description>
<pubDate>Sun, 12 Apr 2020 22:00:00 GMT</pubDate>
<guid isPermaLink="false">b1138074</guid>
</item>
<item>
<title>
Miley Cyrus Gives Cody Simpson a Makeover After Hair Transformation
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1139960/miley-cyrus-gives-cody-simpson-a-makeover-after-hair-transformation?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/2020312//rs_600x600-200412134919-600-miley-cyrus-cody-simpson-makeover-2-instagram-041120.jpg" height="66" width="66" border="0" alt="Miley Cyrus, Cody Simpson, Makeover, Makeup, Instagram" align="left" hspace="5" />Sure you can give your boyfriend a "quarantine haircut," but how about a makeover? Miley Cyrus gave Cody Simpson one on Saturday night as the two practiced social distancing...<br clear="all" />
</description>
<pubDate>Sun, 12 Apr 2020 21:38:35 GMT</pubDate>
<guid isPermaLink="false">b1139960</guid>
</item>
<item>
<title>
Chrissy Teigen's Response to Simone Biles' Handstand Challenge Is All of Us
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1139961/chrissy-teigen-s-response-to-simone-biles-handstand-challenge-is-all-of-us?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/2019913//rs_600x600-191013151453-600-simon-biles-medals-me-101319.jpg" height="66" width="66" border="0" alt="Simone Biles" align="left" hspace="5" />Simone Biles took the handstand challenge to a whole new level. While y'all have already seen stars like Jake Gyllenhaal, Tom Holland and Harrison Osterfield partake in the handstand...<br clear="all" />
</description>
<pubDate>Sun, 12 Apr 2020 20:22:24 GMT</pubDate>
<guid isPermaLink="false">b1139961</guid>
</item>
<item>
<title>
Michelle Money's Daughter Is ''Doing Well'' After Being Moved Out of the ICU
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1139954/michelle-money-s-daughter-is-doing-well-after-being-moved-out-of-the-icu?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/202031//rs_600x600-200401065121-600-Michelle-Money-ch-040120.jpg" height="66" width="66" border="0" alt="Michelle Money" align="left" hspace="5" />Ryan and Michelle Money's daughter "had a big win" with her health. The former couple has been by Brielle's side following her "terrible skateboarding accident" in...<br clear="all" />
</description>
<pubDate>Sun, 12 Apr 2020 20:00:34 GMT</pubDate>
<guid isPermaLink="false">b1139954</guid>
</item>
<item>
<title>
Jessie Cast Shares Memories of Cameron Boyce During Zoom Reunion
</title>
<link>
<![CDATA[
https://www.eonline.com/news/1139936/jessie-cast-shares-memories-of-cameron-boyce-during-zoom-reunion?cmpid=rss-000000-rssfeed-365-topstories&utm_source=eonline&utm_medium=rssfeeds&utm_campaign=rss_topstories
]]>
</link>
<description>
<img src="https://images.eonline.com/resize/66/66//eol_images/Entire_Site/201967//rs_600x600-190707122820-600-cameron-boyce.cm.7719.jpg" height="66" width="66" border="0" alt="Cameron Boyce, Radio Disney Awards" align="left" hspace="5" />Debby Ryan and other former stars of the Disney Channel series Jessie recently reunited on Zoom as they practice social distancing amid the coronavirus pandemic. During the video chat,...<br clear="all" />
</description>
<pubDate>Sun, 12 Apr 2020 19:41:00 GMT</pubDate>
<guid isPermaLink="false">b1139936</guid>
</item>

E在线(美国)-热门故事
https://www.eonline.com/
(美国)-顶级故事
来自娱乐圈、电视、电影、音乐和名人的新闻
美国英语
10
2020年4月13日星期一00:42:22 GMT
2020年4月13日星期一00:42:22 GMT
E在线(美国)-热门故事
120
60
https://www.eonline.com/
https://images.eonline.com/eol_images/Entire_Site/2018223/rs_125x40-180323122205-EGoogleNews.png
©2020 E!娱乐电视有限公司版权所有。,https://www.eonline.com/about/copyright/index.jsp
詹妮弗·洛佩兹和迪迪在Instagram直播上重聚,参加了一场马拉松舞会的募捐活动
谁的舞步更好:詹妮弗·洛佩兹还是肖恩·迪迪·库姆斯?星期天,迪迪请他的名人朋友们站起来为一项事业跳舞。在Instagram上发布,…
这就是rss提要,这是我的代码:

import 'package:http/http.dart' as http;
import 'package:xml/xml.dart' as xml;

class Blogs {
  List<BlogModel> blogs = [];

  Future<void> getBlog() async {
    String url = 'http://syndication.eonline.com/syndication/feeds/rssfeeds/topstories.xml';

    var client = http.Client();
    var response = await client.get(url);
    var rssFeed = response.body;
    var raw = xml.parse(rssFeed);
    var elements = raw.findAllElements('item');

    elements.forEach((element) {
      BlogModel blogModel = BlogModel(
        title: element.findElements('title').first.text,
        url: element.findElements('link').first.text, //This is where I want to get the link in the CDATA
        urlToImage: element.findElements('description').first.text, //This is where I want to get the image src..
        description: element.findElements('description').first.text,
      );
      blogs.add(blogModel);
    });
  }
}
import'package:http/http.dart'作为http;
将“package:xml/xml.dart”导入为xml;
班级博客{
列出博客=[];
Future getBlog()异步{
字符串url='0http://syndication.eonline.com/syndication/feeds/rssfeeds/topstories.xml';
var client=http.client();
var response=wait client.get(url);
var rssFeed=response.body;
var raw=xml.parse(rssFeed);
var元素=原始的findAllElements(“项目”);
elements.forEach((element){
BlogModel BlogModel=BlogModel(
标题:element.findElements('title').first.text,
url:element.findElements('link').first.text,//这是我想要在CDATA中获取链接的地方
urlToImage:element.findElements('description').first.text,//这是我想要获取图像src的地方。。
description:element.findElements('description').first.text,
);
blogs.add(blogModel);
});
}
}
但是我不知道如何访问image标记中src的http字符串

此外,我还需要在链接标记的CDATA中获取http字符串。此代码应该有帮助:

elements.forEach((element) {

   // This will get the image's src.. since it is having problems 
   // with reading the <img>(it is considered as just text 
   // for some reason and not an xml tag).
   // I guess its due to a problem with the encoding of the rss feed
   // So reg-expression has to be used.

   final description = element.findElements('description').first.text;
   final urlRegExp = RegExp(r'(?:(?:https?):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+');
   final imgSrc = urlRegExp.firstMatch(description).group(0);

   // The rest of the parsing.
    BlogModel blogModel = BlogModel(
      title: element.findElements('title').first.text,
      url: element.findElements('link').first.text, //This will get the CDATA content with no problem
      urlToImage: imgSrc,
      description: element.findElements('description').first.text,
    );
    blogs.add(blogModel);
});
elements.forEach((element){
//这将获取映像的src..,因为它有问题

//在阅读的过程中,我遇到了这个问题,我在这里尝试了解决方案,但当时对我无效 我发现这个函数对我很有用

String removeAllHtmlTags(String htmlText) {
RegExp exp = RegExp(
  r"<[^>]*>",
  multiLine: true,
  caseSensitive: true
);

return htmlText.replaceAll(exp, '');}

Moqbel感谢您的回答,但它没有工作。代码没有返回错误,但仍然没有显示图像。E/flatter(32245):[error:flatter/lib/ui/ui_dart_state.cc(157)]未处理的异常:错误状态:无元素E/flatter(32245):#0 Iterable.first(dart:core/Iterable.dart:520:7)E/flatter(32245):#1.getBlog。(软件包:teens#u news/helper/blogs.dart:32:53)E/flatter(32245):#2 Iterable.forEach(dart:core/Iterable.dart:279:30)E/flatter(32245):#3 blogs.getBlog(软件包:teens#u news/helper/blogs.dart:27:17)这真的很奇怪,因为我已经对它进行了测试,它工作得很好。我能想到的唯一解释是,可能您输入代码的xml内容不正确。您发布的xml文件几乎没有问题,我必须清理它,所以我将所有内容都分条,并留下标记,因为它不平衡。这可能就是原因。您可以吗使用API获取xml内容?不,先生,我使用rss源从网站获取xml文件。因此,我非常确定xml文件是正确的,先生,问题是我的代码,您的代码没有返回e
 Response response = await get(
      'your_link',);
     

  if (response.statusCode == 200) {
    var raw = XmlDocument.parse(response.body);
    var elements = raw.findAllElements("stock_available");
    productStock.addAll(elements.map((e) {
      final id = e.findElements('id').single.text;
   
      return StockAvailableProduct(
          id: int.parse(removeAllHtmlTags(id)),
          idProduct:
              removeAllHtmlTags(e.findElements('id_product').single.text),
          idProductAttribute: removeAllHtmlTags(
              e.findElements('id_product_attribute').single.text),
          idShop: removeAllHtmlTags(
              e.findElements('id_shop_group').single.text),
          
    }).toList());
  }