Ich bin Schreiben eines Stack Overflow API-Wrappers , derzeit bei http://soapidotnet.googlecode.com/ . Ich habe ein paar Fragen zum Parsen von SO-RSS-Feeds.
Ich habe mich für die Verwendung von RSS.NET um das RSS zu analysieren, aber ich habe ein paar Fragen zu meinem Code (den ich weiter unten in diesem Beitrag bereitgestellt habe).
Meine Fragen:
Zunächst einmal: Bin ich diese Attribute korrekt zu parsen ? Ich habe eine Klasse namens Question, die diese Eigenschaften hat.
Wie kann ich dann Analysieren Sie die <re:rank>
RSS-Eigenschaft (verwendet für die Anzahl der Stimmen)? Ich bin nicht sicher, wie RSS.NET uns das ermöglicht. Soweit ich verstehe, ist es ein Element mit einem benutzerdefinierten Namespace.
Schließlich muss ich alle Eigenschaften manuell hinzufügen, wie derzeit in meinem Code? Gibt es eine Art von Deserialisierung die ich verwenden kann?
コード
Nachfolgend finden Sie meinen aktuellen Code zum Parsen von Feeds mit aktuellen Fragen:
/// <summary>
/// Utilises recent question feeds to obtain recently updated questions on a certain site.
/// </summary>
/// <param name="site">Trilogy site in question.</param>
/// <returns>A list of objects of type Question, which represents the recent questions on a trilogy site.</returns>
public static List<Question> GetRecentQuestions(TrilogySite site)
{
List<Question> RecentQuestions = new List<Question>();
RssFeed feed = RssFeed.Load(string.Format("http://{0}.com/feeds",GetSiteUrl(site)));
RssChannel channel = (RssChannel)feed.Channels[0];
foreach (RssItem item in channel.Items)
{
Question toadd = new Question();
foreach(RssCategory cat in item.Categories)
{
toadd.Categories.Add(cat.Name);
}
toadd.Author = item.Author;
toadd.CreatedDate = ConvertToUnixTimestamp(item.PubDate).ToString();
toadd.Id = item.Link.Url.ToString();
toadd.Link = item.Link.Url.ToString();
toadd.Summary = item.Description;
//TODO: OTHER PROPERTIES
RecentQuestions.Add(toadd);
}
return RecentQuestions;
}
Hier ist der Code des SO-RSS-Feeds:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:re="http://purl.org/atompub/rank/1.0">
<title type="text">Top Questions - Stack Overflow</title>
<link rel="self" href="http://stackoverflow.com/feeds" type="application/atom+xml" />
<link rel="alternate" href="http://stackoverflow.com/questions" type="text/html" />
<subtitle>most recent 30 from stackoverflow.com</subtitle>
<updated>2009-11-28T19:26:49Z</updated>
<id>http://stackoverflow.com/feeds</id>
<creativeCommons:license>http://www.creativecommons.org/licenses/by-nc/2.5/rdf</creativeCommons:license>
<entry>
<id>http://stackoverflow.com/questions/1813483/averaging-angles-again</id>
<re:rank scheme="http://stackoverflow.com">0</re:rank>
<title type="text">Averaging angles... Again</title>
<category scheme="http://stackoverflow.com/feeds/tags" term="algorithm"/><category scheme="http://stackoverflow.com/feeds/tags" term="math"/><category scheme="http://stackoverflow.com/feeds/tags" term="geometry"/><category scheme="http://stackoverflow.com/feeds/tags" term="calculation"/>
<author><name>Lior Kogan</name></author>
<link rel="alternate" href="http://stackoverflow.com/questions/1813483/averaging-angles-again" />
<published>2009-11-28T19:19:13Z</published>
<updated>2009-11-28T19:26:39Z</updated>
<summary type="html">
<p>I want to calculate the average of a set of angles.</p>
<p>I know it has been discussed before (several times). The accepted answer was <strong>Compute unit vectors from the angles and take the angle of their average</strong>.</p>
<p>However this answer defines the average in a non intuitive way. The average of 0, 0 and 90 will be <strong>atan( (sin(0)+sin(0)+sin(90)) / (cos(0)+cos(0)+cos(90)) ) = atan(1/2)= 26.56 deg</strong> </p>
<p>I would expect the average of 0, 0 and 90 to be 30 degrees.</p>
<p>So I think it is fair to ask the question again: How would you calculate the average, so such examples will give the intuitive expected answer.</p>
</summary>
</entry>
usw.
Hier ist meine Frageklasse, falls es hilft:
/// <summary>
/// Represents a question.
/// </summary>
public class Question : Post //TODO: Have Question and Answer derive from Post
{
/// <summary>
/// # of favorites.
/// </summary>
public double FavCount { get; set; }
/// <summary>
/// # of answers.
/// </summary>
public double AnswerCount { get; set; }
/// <summary>
/// Tags.
/// </summary>
public string Tags { get; set; }
}
/// <summary>
/// Represents a post on Stack Overflow (question, answer, or comment).
/// </summary>
public class Post
{
/// <summary>
/// Id (link)
/// </summary>
public string Id { get; set; }
/// <summary>
/// Number of votes.
/// </summary>
public double VoteCount { get; set; }
/// <summary>
/// Number of views.
/// </summary>
public double ViewCount { get; set; }
/// <summary>
/// Title.
/// </summary>
public string Title { get; set; }
/// <summary>
/// Created date of the post (expressed as a Unix timestamp)
/// </summary>
public string CreatedDate
{
get
{
return CreatedDate;
}
set
{
CreatedDate = value;
dtCreatedDate = StackOverflow.ConvertFromUnixTimestamp(StackOverflow.ExtractTimestampFromJsonTime(value));
}
}
/// <summary>
/// Created date of the post (expressed as a DateTime)
/// </summary>
public DateTime dtCreatedDate { get; set; }
/// <summary>
/// Last edit date of the post (expressed as a Unix timestamp)
/// </summary>
public string LastEditDate
{
get
{
return LastEditDate;
}
set
{
LastEditDate = value;
dtLastEditDate = StackOverflow.ConvertFromUnixTimestamp(StackOverflow.ExtractTimestampFromJsonTime(value));
}
}
/// <summary>
/// Last edit date of the post (expressed as a DateTime)
/// </summary>
public DateTime dtLastEditDate { get; set; }
/// <summary>
/// Author of the post.
/// </summary>
public string Author { get; set; }
/// <summary>
/// HTML of the post.
/// </summary>
public string Summary { get; set; }
/// <summary>
/// URL of the post.
/// </summary>
public string Link { get; set; }
/// <summary>
/// RSS Categories (or tags) of the post.
/// </summary>
public List<string> Categories { get; set; }
}
Vielen Dank im Voraus! Übrigens: Bitte unterstützen Sie das Bibliotheksprojekt! :)