用于 Repeater 的 ItemDataBound 内的 Xpath
好的,我使用 XMLDataSource 和中继器从 feedburner 中提取 XML 提要。
<asp:Repeater ID="rptrEvents" OnItemDataBound="rptrEvents_ItemDataBound" DataSourceID="XmlDataSource1" runat="server">
<ItemTemplate>
<li runat="server" id="liLineItem">
<a href="<%#XPath("link")%>">
<span><%#XPath("pubdate")%></span>
<%#XPath("title")%>
</a>
</li>
</ItemTemplate>
</asp:Repeater>
现在我遇到的问题是,“pubdate”是空的,标题包括标题和日期[尽管它可以很容易地被分割,因为日期总是以 : (冒号)结尾,
所以我需要能够做到这在后面的代码中。
但是,我无法让它在后面的代码中工作。
我已经尝试过类似的方法(现在承认,我在 XML 方面是个新手)
IXPathNavigable x = (IXPathNavigable)e.Item.DataItem;
XPathNavigator nav = x.CreateNavigator();
XmlElement xePage = (XmlElement)nav.UnderlyingObject;
string title = xePage.GetAttribute("title");
所以我尝试了这个,但 xePage 总是将“HasAttributes”显示为 false,并且从未找到标题。 xePage.InnerXML 似乎包含正确的数据,但我不想尝试手动解析内容。
谁能指出我做错了什么的更好方向?
谢谢!
Okay so I'm pulling in an XML feed from feedburner, using an XMLDataSource and a repeater.
<asp:Repeater ID="rptrEvents" OnItemDataBound="rptrEvents_ItemDataBound" DataSourceID="XmlDataSource1" runat="server">
<ItemTemplate>
<li runat="server" id="liLineItem">
<a href="<%#XPath("link")%>">
<span><%#XPath("pubdate")%></span>
<%#XPath("title")%>
</a>
</li>
</ItemTemplate>
</asp:Repeater>
Now the problem I'm running into is, "pubdate" is empty, and title includes both the title and date [though it can easily be split because the date always ends in a : (colon)
So I need to be able to do this in the code behind.
However, I'm unable to get this to work in the code behind.
I've tried something like this (now granted, I'm a total newb when it comes to XML)
IXPathNavigable x = (IXPathNavigable)e.Item.DataItem;
XPathNavigator nav = x.CreateNavigator();
XmlElement xePage = (XmlElement)nav.UnderlyingObject;
string title = xePage.GetAttribute("title");
So I tried this, but xePage always shows "HasAttributes" as false, and never finds the title. xePage.InnerXML seems to contain the proper data, but I don't want to try and parse things out manually.
Can anyone point me in a better direction on what I'm doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
OnItemBound
事件中尝试此操作。In your
OnItemBound
event try this instead.