Skulle bli tacksam om jag kunde få feedback på min kod. Den fungerar, men jag är osäker på om man verkligen behöver deklarera så många itereringsobjekt. Finns det något bättre sätt att göra det på? Feedback på kod
private bool LoadXml(string url)
{
try
{
XmlDocument xmlText = new XmlDocument();
xmlText.Load(url);
XPathNavigator path = xmlText.CreateNavigator();
XPathNodeIterator headtitle = path.Select("/rss/channel/title[1]");
XPathNodeIterator headlink = path.Select("/rss/channel/link[1]");
XPathNodeIterator headdescription = path.Select("/rss/channel/description[1]");
XPathNodeIterator title = path.Select("/rss/channel/item/title");
XPathNodeIterator link = path.Select("/rss/channel/item/link");
XPathNodeIterator description = path.Select("/rss/channel/item/description");
headtitle.MoveNext();
HyperLink headhyperLink = new HyperLink();
headhyperLink.Text = headtitle.Current.Value;
headlink.MoveNext();
headhyperLink.NavigateUrl = headlink.Current.Value;
headdescription.MoveNext();
headhyperLink.ToolTip = headdescription.Current.Value;
headhyperLink.Target = "_blank";
headhyperLink.CssClass = "rsshead";
this.right.Controls.Add(headhyperLink);
this.right.Controls.Add(new LiteralControl("<br />"));
while (title.MoveNext())
{
HyperLink hyperLink = new HyperLink();
hyperLink.Text = title.Current.Value;
link.MoveNext();
hyperLink.NavigateUrl = link.Current.Value;
description.MoveNext();
hyperLink.ToolTip = description.Current.Value;
hyperLink.Target = "_blank";
hyperLink.CssClass = "rss";
this.right.Controls.Add(hyperLink);
this.right.Controls.Add(new LiteralControl("<br />"));
}
return true;
}
catch{ return false; }