private TreeNode NewCommentTreeNode(XPathNavigator comment, string prefix=null)
{
string s = prefix==null ? "" : prefix;
s+=comment.SelectSingleNode("short-name").ToString() + " " + comment.SelectSingleNode("author").ToString() + " " + comment.SelectSingleNode("date").ToString() + ": ";
var commentbody = comment.SelectSingleNode("body").ToString();
var commenttype = comment.SelectSingleNode("content-type").ToString();
switch (commenttype)
{
case "text/plain":
if (commentbody.Length <= 48)
s += commentbody;
else
s += commentbody.Substring(0, 48) + " ...";
break;
case "text/html":
int idx=0, count = 0;
bool inhtml = false;
for (; count < 48 && idx<commentbody.Length; idx++)
{
if (inhtml)
{
if (commentbody[idx] == '>')
inhtml = false;
}
else
{
if (commentbody[idx] == '<')
inhtml = true;
else
{
s += commentbody[idx];
count++;
}
}
}
if (idx < commentbody.Length) s += " ...";
break;
default:
s += commenttype;
break;
}
return new TreeNode(s);
}