如何显示xml文件中的视频?

2024-02-11

您好,我使用下面给出的 xml 文件,如何从 xml 文件获取视频?

<Category name="Videos">
   <article articleid="68">
     <videourl>
      <iframe src="http://player.vimeo.com/video/52375409?fullscreen=0" width="500"   height="298" frameborder="0"></iframe>
     </videourl>
    </article>
</Category>

我的代码是

XDocument loadedData = XDocument.Load("CountriesXML.xml");

        var data = from query in loadedData.Descendants("Country")
          select new CountryData
          {
             url = (string)query.Element("videourl").Elements("iframe").Single().Attribute("src").Value,
          };
     countryList = data.ToList();

但我收到 NullReferenceException 错误


var xdoc = XDocument.Load("CountriesXML.xml");
var videos = from f in xdoc.Descendants("iframe")
             select new {
                Src = (string)f.Attribute("src"),
                Width = (int)f.Attribute("width"),
                Height = (int)f.Attribute("height")
             };

或者使用您更新的代码:

var xdoc = XDocument.Load("CountriesXML.xml");
var data = from c in xdoc.Descendants("Category") // you have Category element
           select new CountryData {
              url = (string)c.Element("article") // there is also article element
                             .Element("videourl")
                             .Elements("iframe")
                             .Single().Attribute("src")
           };
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何显示xml文件中的视频? 的相关文章

随机推荐