[英]How do I limit the number of characters shown in an XML record in asp.net?
[英]How do I limit the number of records shown in an XML feed in asp.net?
我试图限制传递给asp.net中继器的XML提要中的记录数。
有数百个“记录”,我想将转发器限制为4个。
任何帮助表示赞赏。 谢谢!
我后面的代码:
protected void XMLsource()
{
string URLString = "http://ExternalSite.com/xmlfeed.asp";
XmlDataSource x = new XmlDataSource();
x.DataFile = URLString;
x.XPath = String.Format(@"root/mainNode");
xPathRepeater.DataSource = x;
xPathRepeater.DataBind();
}
还有我的前端代码:
<asp:Repeater ID="xPathRepeater" runat="server">
<ItemTemplate>
<li>
<h1><%#XPath ("title") %></h1>
</li>
</ItemTemplate>
</asp:Repeater>
xPathRepeater.DataSource = x.Data.Take(4);
xPathRepeater.DataBind();
或者:
x.XPath = String.Format(@"root/mainNode [position() < 5]");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.