测试简单读取opml
2017-02-15 10:20
176 查看
opml文件模拟以下default.opml
public MainWindow()
{
InitializeComponent();
tx_1.Text = “”;
ReadOpml();
当然把准备好的default.opml预先拷贝到自己的debug目录下。
效果图,但是这样是远远不够,的创建一个数据类型(list),来承接这些text,因为到时候要绑定到treeview中的。
<?xml version="1.0" encoding="UTF-8"?> <opml version="1.0"> <head> <title>NewsFox OPML Export</title> <dateModified>Fri Dec 16 2016 16:21:16 GMT+0800</dateModified> </head> <body> <outline text="源" type="NFgroup"> <outline type="rss" text="Engadget 中国版" xmlUrl="http://cn.engadget.com/rss.xml" htmlUrl="http://cn.engadget.com" /> <outline type="rss" text="糗事百科" xmlUrl="http://feed.feedsky.com/qiushi" htmlUrl="http://www.qiushibaike.com/" /></outline> <outline text="科技" type="NFgroup"> <outline type="rss" text="cnBeta.COM业界资讯" xmlUrl="http://fullrss.net/a/http/cnbeta.feedsportal.com/c/34306/f/624776/index.rss" htmlUrl="http://www.cnbeta.com"/> <outline type="rss" text="小众软件" xmlUrl="http://fullrss.net/a/http/feed.appinn.com/" htmlUrl="http://www.appinn.com"/> </outline></body> </opml> 读带有目录的就特别的麻烦,尤其是多层的或者无限层的就要用到递归。这里一般就只有两层,所以用for循环了。 界面写个textbox显示读取的数据
<Grid> <TextBox Name="tx_1" TextWrapping="Wrap" Text="随便写写绑定用" /> </Grid>
mainwindow.cs下
public MainWindow()
{
InitializeComponent();
tx_1.Text = “”;
ReadOpml();
} private void ReadOpml() { string str = System.AppDomain.CurrentDomain.BaseDirectory; if (File.Exists("default.opml")) { XmlDocument doc = new XmlDocument(); doc.Load("default.opml"); XmlNodeList otls = doc.GetElementsByTagName("outline"); for (int i = 0; i < otls.Count; i++) { if (otls[i].Attributes.GetNamedItem("type").InnerText == "NFgroup") { tx_1.Text += Environment.NewLine + otls[i].Attributes.GetNamedItem("text").InnerText + otls[i].Attributes.GetNamedItem("type").InnerText + Environment.NewLine; continue; } else { tx_1.Text += otls[i].Attributes.GetNamedItem("text").InnerText + Environment.NewLine; } // createList(otls[i].Attributes.GetNamedItem("text").InnerText); } } else { MessageBox.Show("没有opml文件,创建一个空的default.opml"); File.Create("default.opml"); } }
当然把准备好的default.opml预先拷贝到自己的debug目录下。
效果图,但是这样是远远不够,的创建一个数据类型(list),来承接这些text,因为到时候要绑定到treeview中的。
相关文章推荐
- 父子进程同时读取文件的简单测试
- XML的简单读取与写入
- 用NUnit2.1简单实现.net的测试驱动开发(TDD)
- XML的简单读取与写入
- XML的简单读取与写入
- Hibernate的简单Read性能测试
- ASP.NET + C#读取ACCESS数据库内容的简单方法
- 一次读取大Size Jpeg图的测试
- C#版简易RSS阅读器(新增读取OPML功能)
- XML的简单读取与写入
- 代码测试的简单框架
- 如何用ping 命令简单测试网速
- 关于DB2的简单并行性能测试
- Hibernate性能测试(load10000条记录的简单测试 仅供参考)
- Linux下Apache2.0简单安装、配置、测试过程
- 简单的横向菜单测试
- 三种分页方式效率的简单测试
- 【原创】Jsp读取文件(简单的计数器)
- XML的简单读取与写入
- 使用简单的J2ME程序测试MIDlet的生命周期