以下是部分XML代码,是远程电脑上的。只给提供了个url地址。- <videos>
- <video>
<title>2007年感动人物候选人:话剧团</title>
<createtime>1287560484</createtime>
<views>12</views>
<img>/attachment/11/snapshot/46f6215956d7c46255d00263c715c9d4.jpg</img>
<link>player.php?id=32448</link>
</video>
- <video>
<title>2007年感动人物候选人:马庆怀</title>
<createtime>1287561196</createtime>
<views>16</views>
<img>/attachment/11/snapshot/2367a2216a3ec74c8c6dd02123836612.jpg</img>
<link>player.php?id=32454</link>
</video>
- <video>
<title>2007年感动人物候选人:樊有军</title>
<createtime>1287561973</createtime>
<views>17</views>
<img>/attachment/11/snapshot/df461bdc860cb693713eb0de173f6937.jpg</img>
<link>player.php?id=32456</link>
</video>
</videos>
- <video>
<title>2007年感动人物候选人:话剧团</title>
<createtime>1287560484</createtime>
<views>12</views>
<img>/attachment/11/snapshot/46f6215956d7c46255d00263c715c9d4.jpg</img>
<link>player.php?id=32448</link>
</video>
- <video>
<title>2007年感动人物候选人:马庆怀</title>
<createtime>1287561196</createtime>
<views>16</views>
<img>/attachment/11/snapshot/2367a2216a3ec74c8c6dd02123836612.jpg</img>
<link>player.php?id=32454</link>
</video>
- <video>
<title>2007年感动人物候选人:樊有军</title>
<createtime>1287561973</createtime>
<views>17</views>
<img>/attachment/11/snapshot/df461bdc860cb693713eb0de173f6937.jpg</img>
<link>player.php?id=32456</link>
</video>
</videos>
下面是 DataSetXml.cs文件代码namespace Va.Common
{
public class DataSetXml
{
#region GetDataSetByXml
/// 读取xml直接返回DataSet
/// xml文件相对路径
public static DataSet GetDataSetByXml(string strXmlPath)
{
StringReader StrStream = null;
XmlTextReader Xmlrdr = null;
try
{
XmlDocument doc = new XmlDocument();
DataSet ds = new DataSet();
doc.Load(strXmlPath);
//读取文件中的字符流
StrStream = new StringReader(doc.InnerXml);
//获取StrStream中的数据
Xmlrdr = new XmlTextReader(StrStream); ds.ReadXml(Xmlrdr); XmlNodeList nodeList = doc.GetElementsByTagName("video");
if (doc.HasChildNodes)
{ foreach (XmlNode node in nodeList)
{
if (node.HasChildNodes)
{
string title = string.Empty, link = string.Empty, pubDate = string.Empty, views = string.Empty, img = string.Empty;
XmlNodeList subNodeList = node.ChildNodes;
foreach (XmlNode subNode in subNodeList)
{
switch (subNode.Name.ToLower())
{
case "title":
title = subNode.InnerText;
ds.Tables[0].Rows.Add("title");
ds.Tables[0].Rows[0]["title"].Equals(title);
break;
case "link":
link = subNode.InnerText;
ds.Tables[0].Rows.Add("link");
ds.Tables[0].Rows[0]["link"].Equals(title);
break;
case "pubdate":
pubDate = subNode.InnerText;
ds.Tables[0].Rows.Add("pubDate");
ds.Tables[0].Rows[0]["pubDate"].Equals(pubDate);
break;
case "views":
views = subNode.InnerText;
ds.Tables[0].Rows.Add("views");
ds.Tables[0].Rows[0]["views"].Equals(pubDate);
break;
case "img":
img = subNode.InnerText;
ds.Tables[0].Rows.Add("img");
ds.Tables[0].Rows[0]["img"].Equals(img);
break; }
if (title != string.Empty && link != string.Empty && pubDate != string.Empty && views != string.Empty && img != string.Empty)
break;
} }
}
} return ds;
}
catch (Exception e)
{
throw e;
}
finally
{
////释放资源
//if (Xmlrdr != null)
//{
// Xmlrdr.Close();
// StrStream.Close();
// StrStream.Dispose();
//}
}
}
#endregion }
}aspx文件部分代码:
<asp:Repeater ID="rptContent" runat="server">
<ItemTemplate>
<li><a href="http://xxxxx/<%#Eval("link") %>" target="_blank"><img class="play_sp_more2_b" border="0" alt="<%#Eval("title") %>" src="http://xxx/<%#Eval("img") %>" /></a><br /> <a
href="http://xxx/<%#Eval("link") %>"><span><%#Eval("title") %></span></a><br />
播放:<%#Eval("views") %> </li>
</ItemTemplate>
</asp:Repeater>aspx.cs文件部分代码:public partial class index : System.Web.UI.Page
{
public string tag = string.Empty;
public string url = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
url = "http://xxxx.com/x.xml";
if (!IsPostBack)
{
BindData(); }
}
protected void BindData()
{
rptContent.DataSource = DataSetXml.GetDataSetByXml(url).Tables[0].DefaultView;
rptContent.DataBind();
Pager.RecordCount = Convert.ToInt32(41);
Pager.CustomInfoHTML = string.Format("当前第{0}/{1}页 共{2}条记录 每页{3}条", Pager.CurrentPageIndex, Pager.PageCount, Pager.RecordCount, Pager.PageSize);
}
protected void Pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
Pager.CurrentPageIndex = e.NewPageIndex;
BindData();
}以下是部分xml文件代码:
- <videos>
- <video>
<title>2007年感动人物候选人:话剧团</title>
<createtime>1287560484</createtime>
<views>12</views>
<img>/attachment/11/snapshot/46f6215956d7c46255d00263c715c9d4.jpg</img>
<link>player.php?id=32448</link>
</video>
- <video>
<title>2007年感动人物候选人:马庆怀</title>
<createtime>1287561196</createtime>
<views>16</views>
<img>/attachment/11/snapshot/2367a2216a3ec74c8c6dd02123836612.jpg</img>
<link>player.php?id=32454</link>
</video>
- <video>
<title>2007年感动人物候选人:樊有军</title>
<createtime>1287561973</createtime>
<views>17</views>
<img>/attachment/11/snapshot/df461bdc860cb693713eb0de173f6937.jpg</img>
<link>player.php?id=32456</link>
</video>
</videos>
<video>
<title>2007年感动人物候选人:樊有军</title>
<createtime>1287561973</createtime>
<views>17</views>
<img>/attachment/11/snapshot/df461bdc860cb693713eb0de173f6937.jpg</img>
<link>player.php?id=32456</link>
</video>算一条记录