|
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
/*
<post>
<id type="integer">#{id}</id>
<title>#{title}</title>
<posted-on type="datetime">#{posted_on}</posted-on>
<attachments-count type="integer">#{attachments_count}</attachments-count>
<category>
<id type="integer">#{id}</id>
<name>#{name}</name>
</category>
</post>
*/
public class AbbreviatedPost {
private int _ID;
public int ID {
get {
return _ID;
}
set {
_ID = value;
}
}
private string _Title;
public string Title {
get {
return _Title;
}
set {
_Title = value;
}
}
private DateTime _Posted;
public DateTime Posted {
get {
return _Posted;
}
set {
_Posted = value;
}
}
private PostCategory _Category;
public PostCategory Category {
get {
return _Category;
}
set {
_Category = value;
}
}
public AbbreviatedPost(int id, string title, DateTime posted, PostCategory category) {
_ID = id;
_Title = title;
_Posted = posted;
_Category = category;
}
public static IList<AbbreviatedPost> Parse(XmlNodeList postNodes) {
IList<AbbreviatedPost> abbreviatedPosts = new List<AbbreviatedPost>();
foreach (XmlElement node in postNodes) {
int id = int.Parse(node.GetElementsByTagName("id").Item(0).InnerText);
string title = node.GetElementsByTagName("title").Item(0).InnerText;
DateTime posted = DateTime.Parse(node.GetElementsByTagName("posted-on").Item(0).InnerText);
IList<PostCategory> categories = PostCategory.Parse(node.SelectNodes("category"), true);
AbbreviatedPost p = new AbbreviatedPost(id, title, posted, categories[0]);
abbreviatedPosts.Add(p);
}
return abbreviatedPosts;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.