如何显示来自xml文件的视频? [英] How to display video from xml file?
本文介绍了如何显示来自xml文件的视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我使用xml文件,如何从xml文件中获取视频?
< Category name =视频>
< article articleid =68>
< videourl>
< iframe src =http://player.vimeo.com/video/52375409?fullscreen=0width =500height =298frameborder =0>< / iframe>
< / videourl>
< / article>
< / Category>
我的代码是
XDocument loadedData = XDocument.Load(CountriesXML.xml);
var data = from loadData.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)
};
<$ p $ p> var xdoc = XDocument.Load(CountriesXML.xml);
var data = from c in xdoc.Descendants(Category)//你有Category元素
select new CountryData {
url =(string)c.Element(article)/ /还有article元素
.Element(videourl)
.Elements(iframe)
.Single()。
Hi am using xml file given below,how can i get videos from xml file?
<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>
My Code is
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();
but i got NullReferenceException error
解决方案
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")
};
Or with your updated code:
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")
};
这篇关于如何显示来自xml文件的视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文