Question

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!

Was it helpful?

Solution

In your OnItemBound event try this instead.

protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    IXPathNavigable x = (IXPathNavigable)e.Item.DataItem;
    XPathNavigator nav = x.CreateNavigator();
    XmlElement xePage = (XmlElement)nav.UnderlyingObject;
    string title = xePage.SelectSingleNode("title").InnerText;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top