I followed this tutorial Use external RSS feed in ASP.NET website - Visual Studio 2010
To try and display a Facebook rss feed on my website.
This was the resulting code:
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListView1" runat="server" DataSourceID="XmlDataSource1">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><%#XPath("title") %></li>
</ItemTemplate>
</asp:ListView>
</div>
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="http://feeds.bbci.co.uk/news/rss.xml?edition=uk"
XPath="rss/channel/item"></asp:XmlDataSource>
</form>
With nothing in the codebehind file.
This seem to work with pretty much any RSS feed. But if I try with my Facebook RSS feed:
http://www.facebook.com/feeds/page.php?format=rss20&id=1425042407719904
It falls over with the following error:
An error occurred while parsing EntityName. Line 9, position 30.
Is there something extra needs doing when consuming/parsing a Facebook RSS feed?
Thanks.
Ok. Never did find the reason for this. In the end I routed the feed via feedburner.com which seemed to resolve the issue.
Related
I'm pretty new to using XML and very new to XPath.
I'm trying to select a field in my XML document and display that in a label on a webpage. Sound nice and simple.
Here is the code on my webpage:
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="NewsListView" runat="server" DataSourceID="NewsDataSource">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" ><%#XPath("temp1")%></asp:Label>
</ItemTemplate>
</asp:ListView>
<asp:XmlDataSource ID="NewsDataSource" runat="server" DataFile="~/news.xml"></asp:XmlDataSource>
</div>
</form>
</body>
This works 100% fine when using a XML document like the one below.
<test>
<response>
<temp1>23.7</temp1>
</response>
</test>
But the XML document I am trying to access, which I cannot change looks like this:
<response>
<temp1>23.7</temp1>
</response>
Basically the same document but without the extra node at the top.
Is there anyway I can get XPath to read the value of temp1 without the extra node?
Thanks.
Im not familiar with xpath but looking at documentation.. can you add
<asp:Repeater
id="Repeater1"
runat="server"
DataSource='<%# XPathSelect("response") %>' >
Found a solution. Adding XPath="/response" to the XMLDataSource did the trick.
I have never tried this API before, but does it work to do something like this?
<%#XPath("temp1/text()")%>
This xpath should return the text of the temp1 element.
What I am trying to achieve is to get the full path of the images, assigning them to the source attribute of the HTML image control. This image is placed within a Repeater Control.
Here the code:
<asp:Repeater runat="server" ID="flashImagesRepeater" >
<HeaderTemplate>
<table>
<tr id="bodyImagesTr" >
<td>
</HeaderTemplate>
<ItemTemplate>
<sc:Link ID="flashImageClickURL" runat="server" Field="Click Url" Item="<%# Container.DataItem %>" >
<img id="htmlImage" runat="server" field="Image" src="<%# MediaManager.GetMediaUrl(((ImageField)((Item)Container.DataItem).Fields["Image"]).MediaItem) %>" />
</sc:Link>
</ItemTemplate>
<FooterTemplate>
</td>
</tr>
</table>
</FooterTemplate>
Also made sure that I have the relevant namespace added <%# Import Namespace="Sitecore.Resources.Media" %> at the top.
But VS2010 gives me the error
Cannot resolve symbol 'MediaItem'
Can someone guide me as to what am I doing wrong?
May be the brackets are being being placed incorrectly?
Thanks for reading.
You definitely don't need to write anything in the code behind. It looks like for some reason one of the classes in you statement is considered as not from the one of the Sitecore namespaces. Try to use full class names with namespaces:
<img
id="htmlImage"
runat="server"
field="Image"
src="<%# Sitecore.Resources.Media.MediaManager.GetMediaUrl(((Sitecore.Data.Fields.ImageField)((Sitecore.Data.Items.Item)Container.DataItem).Fields["Image"]).MediaItem) %>"
/>
Looks like you're trying to render an image from a field in an item, just use the FieldRender control and let Sitecore handle it.
<sc:FieldRenderer runat="server" FieldName="Image" Item="<%# (Item)Container.DataItem %>" />
I think the problem you are having is that there is that ImageField is not resolving to the Sitecore image field correctly. I pasted that code into an aspx page and I got another error saying that the Field could not be cast as an ImageField. So I added the sitecore name space to the ImageField conversion and it properly intellisensed MediaItem as you wanted.
So change the image tag to this and it should work:
<img id="htmlImage" runat="server" field="Image" src="<%# MediaManager.GetMediaUrl(((Sitecore.Data.Fields.ImageField)((Item)Container.DataItem).Fields["Image"]).MediaItem) %>" />
Personally tho - I would use the Sitecore Image control to render the image, if you just want to find the media Url in back end code, the above code would work but could be written a lot more readable :)
Hope this helps!
EDIT Final: Just in case someone else sees this behavior, I wanted to explain my work around. I was using a placeholder on my Master page for the webform described below. I added a server control to the placeholder in the Master page OnInit event. Through a process of elimination, I figured out that the behavior described below only happens when I add this server control to the Master page.
titlebarPlaceHolder.Controls.Add(sctitlebar)
I re-wrote the Master Page to not need the server control added and the behavior described below went away. I have no idea what caused it. It was a simple server control, but this is my work around.
EDIT 2: The same behavior happens when the container is a table in the repeater control:
<asp:Repeater ID="rptAuditList" runat="server">
<ItemTemplate>
<tr class="odd">
<td><asp:LinkButton ID="lnkOpenAudit" runat="server" Text='<%# Eval("auditname") %>'></asp:LinkButton> </td>
</tr>
</ItemTemplate>
</asp:Repeater>
Here is the HTML output:
<td>Demo PreClose July 2012 </td>
EDIT: In my testing I just noticed that if I run the extact same control OUTSIDE of a MasterPage, it worked correctly, but if I run it inside a MasterPage, it behaves in the way described below.
I have tried this with a Repeater, DataList and Listview and the results are always the same.
Here is the HTML:
<asp:ListView ID="lvwAuditList" runat="server" >
<LayoutTemplate>
<ul><li runat="server" id="itemPlaceholder"></li></ul>
</LayoutTemplate>
<ItemTemplate>
<li><asp:LinkButton ID="lnkAudit" runat="server" Text='<%# Eval("auditname") %>' >
</asp:LinkButton></li>
</ItemTemplate>
</asp:ListView>
Here is the output:
<ul>
<li>Demo PreClose July 2012</li>
<li><a id="contentMain_lvwAuditList_lnkAudit_1" href="javascript:__doPostBack('ctl00$contentMain$lvwAuditList$ctrl1$lnkAudit','')">Demo PostClose Audit June 2012</a></li>
</ul>
The first row always has an extra href="" added. I have never seen this behavior before. I have stripped down the html and code behind to its most basic, yet I still get this extra href="". The code behind just sets the datasource and binds it, nothing else.
Thank you.
If you are using the first list tag as a placeholder and replacing the content in the code behind I would use a slightly different approach adding an ASP.NET PlaceHolder inside the list tag as follows:
<ul><li><asp:PlaceHolder runat="server" ID="itemPlaceholder" /></li></ul>
I have experienced some unusual artefacts appearing in Response code when using ASP.NET tags in a manner for which they were not particularly intended. This may well be causing your problem as well!
Using an ASP.Net LoginView, 2 sets of UserName and Password TextBoxes are displayed.
Using this markup, can you tell us how to only show 1 set of the UserName and Password TextBoxes from the AnonymousTemplate?
<asp:UpdatePanel
ID="UpdatePanelParentsSummary"
runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<div class="Menu">
<asp:LoginView
ID="loginViewMain"
runat="server">
<AnonymousTemplate>
<asp:LoginStatus
ID="loginStatus"
runat="server" />
<asp:Login runat="server" ID="login"></asp:Login>
</AnonymousTemplate>
<LoggedInTemplate>
<asp:LoginName
ID="loginName"
runat="server"
FormatString="Hello, {0}!<br/><br/> You have successfully<br/> logged onto the staff site." />
(<asp:LoginStatus ID="loginStatus" runat="server" />)
<asp:SiteMapDataSource
id="KnowledgeAcademySiteMap"
runat="server"
ShowStartingNode="false" />
<asp:TreeView
id="TreeViewMain"
runat="server"
ExpandDepth="0"
OnTreeNodeExpanded="TreeViewMain_TreeNodeExpanded"
DataSourceID="KnowledgeAcademySiteMap">
<RootNodeStyle ImageUrl="/Images/book.png" />
<ParentNodeStyle ImageUrl="/Images/book.png" />
<LeafNodeStyle ImageUrl="/Images/book.png" />
</asp:TreeView>
</LoggedInTemplate>
</asp:LoginView>
</div>
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
With the markup shown, there should be only one <asp:Login> control displayed. There must be some other markup or code that is affecting this.
The best option at this point would be to debug the problem by adding some additional content that will help figure out where everything is coming from. For example, you could try the following:
Enable Tracing in the page by setting Trace=true in the #Page directive at the top of the ASPX file. That will render a graph of the control tree at the bottom of the page, which might help you figure out where the other Login control is.
Add some dummy markup immediately before and after the Login control that you see, such as putting the text BEGINBEGINBEGIN right before it, and ENDENDEND right after it. If you see that rendering once, then there's a different Login control coming from somewhere else. If you see it rendering twice, then something is causing the whole control to render twice, which must be coming from some custom code that is not being shown.
Start removing bits and pieces of the page to simplify it, until you figure out what is causing the difference.
I m adding rss feed in out publish website which is related to advocate .
Create an XML file according to the RSS standard.
If you are using database driven website, you can manipulate a dynamic RSS feed from your DB. Assuming you are using PHP you can find the instruction on this link to create dynmic RSS feeds. http://www.broculos.net/tutorials/how_to_make_a_dynamic_rss_feed_in_php/20080324/en
try this:
http://weblogs.asp.net/scottgu/archive/2006/02/22/Awesome-ASP.NET-2.0-RSS-Tool_2D00_Kit-Released.aspx
<asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1">
<ItemTemplate>
Title: <%# XPath("title") %><br />
Pulish Date: <%# XPath("pubDate") %><br />
Description: <%# XPath("description") %>
<hr />
</ItemTemplate>