概要
cscの作法、調べてみた。
練習問題やってみた。
練習問題
treeviewで、xmlを表示せよ。
方針
- qiitaのfeed使う。
写真
サンプルコード
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using System.Net;
using System.Net.Http;
using System.Xml;
using System.Xml.Linq;
class FormMain: Form {
private TreeView tv;
FormMain() {
Text = "xml";
Size = new Size(700, 700);
tv = new TreeView();
tv.Location = new Point(20, 20);
tv.Size = new Size(600, 600);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
XNamespace xNamespace = @"http://www.w3.org/2005/Atom";
var feed = XDocument.Load(@"https://qiita.com/popular-items/feed");
//Console.WriteLine(feed);
tv.Nodes.Add(CreateTreeNode(feed.Root));
this.Controls.Add(tv);
}
private TreeNode CreateTreeNode(XElement elCurr) {
TreeNode tnCurr = new TreeNode(elCurr.Value.ToString());
if (elCurr.HasElements)
{
foreach (var elChild in elCurr.Elements())
{
tnCurr.Nodes.Add(CreateTreeNode(elChild));
}
}
return tnCurr;
}
[STAThread]
public static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
}
}
以上。