資源簡介
wince下的C#讀取xml文件,wince智能項目不支持相對路徑,所以沒有Setting.setting配置文件,所以需要讀寫xml,下載文件中有詳細(xì)說明

代碼片段和文件信息
using?System;
using?System.Linq;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.xml;
namespace?SmartDevicexmlTest
{
????public?partial?class?Form1?:?Form
????{
????????string?filename?=?““;
????????
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?btWrite_Click(object?sender?EventArgs?e)
????????{
????????????
????????????xmlDocument?xmlDoc?=?new?xmlDocument();??
????????????xmlDoc.Load(filename);??
????????????//xmlDoc.Loadxml(“ “);??
????????????xmlNode?root?=?xmlDoc.SelectSingleNode(“bookstore“);//查找 ??
????????????xmlElement?xe1?=?xmlDoc.CreateElement(“book“);//創(chuàng)建一個 節(jié)點??
????????????xe1.SetAttribute(“genre“?“李贊紅“);//設(shè)置該節(jié)點genre屬性??
????????????xe1.SetAttribute(“ISBN“?“2-3631-4“);//設(shè)置該節(jié)點ISBN屬性??
???
????????????xmlElement?xesub1?=?xmlDoc.CreateElement(“title“);??
????????????xesub1.InnerText?=?“CS從入門到精通“;//設(shè)置文本節(jié)點??
????????????xe1.AppendChild(xesub1);//添加到 節(jié)點中??
????????????xmlElement?xesub2?=?xmlDoc.CreateElement(“author“);??
????????????xesub2.InnerText?=?“候捷“;??
????????????xe1.AppendChild(xesub2);??
????????????xmlElement?xesub3?=?xmlDoc.CreateElement(“price“);??
????????????xesub3.InnerText?=?“58.3“;??
????????????xe1.AppendChild(xesub3);??
???
????????????root.AppendChild(xe1);//添加到 節(jié)點中??
????????????xmlDoc.Save(filename);
????????????//插入完成后讀取信息
????????????//ShowAllInfo(filename?xmlDoc);
????????}
????????private?void?btRead_Click(object?sender?EventArgs?e)
????????{
????????????xmlDocument?xmlDoc?=?new?xmlDocument();
????????????xmlDoc.Load(filename);?
????????????ShowAllInfo(filename?xmlDoc);
????????????//修改完成后讀取信息
????????}
????????private?void?ShowAllInfo(string?tmpfilename?xmlDocument?tmpxmlDoc)
????????{
????????????????textBox1.Text?=?““;
????????????????//xmlNode?xn?=?tmpxmlDoc.SelectSingleNode(“bookstore“);??
??????
????????????????//xmlNodeList?xnl?=?xn.ChildNodes;
????????????????xmlNodeList?xnl?=?tmpxmlDoc.SelectSingleNode(“bookstore“).ChildNodes;
???????????????
????????????????foreach?(xmlNode?xnf?in?xnl)
????????????????{
????????????????????xmlElement?xe?=?(xmlElement)xnf;
????????????????????//Console.WriteLine(xe.GetAttribute(“genre“));//顯示屬性值??
????????????????????//Console.WriteLine(xe.GetAttribute(“ISBN“));
????????????????????textBox1.Text?+=?xe.GetAttribute(“genre“)?+?“\r\n“;
????????????????????textBox1.Text?+=?xe.GetAttribute(“ISBN“)?+?“\r\n“;
????????????????????xmlNodeList?xnf1?=?xe.ChildNodes;
????????????????????foreach?(xmlNode?xn2?in?xnf1)
????????????????????{
????????????????????????//Console.WriteLine(xn2.InnerText);//顯示子節(jié)點點文本??
????????????????????????textBox1.Text?+=?xn2.InnerText+“\r\n“;
????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????516??2009-09-18?09:52??wince?C#?讀寫xm
?????文件??????10240??2011-12-22?15:04??wince?C#?讀寫xm
?????文件??????28160??2011-12-22?15:04??wince?C#?讀寫xm
?????文件????????219??2009-09-18?09:36??wince?C#?讀寫xm
?????文件???????5780??2011-12-22?15:04??wince?C#?讀寫xm
?????文件???????4398??2009-09-18?13:25??wince?C#?讀寫xm
?????文件???????6101??2009-09-18?13:25??wince?C#?讀寫xm
?????文件???????1882??2011-12-22?14:30??wince?C#?讀寫xm
?????文件????????847??2009-09-18?13:30??wince?C#?讀寫xm
?????文件??????10240??2011-12-22?15:04??wince?C#?讀寫xm
?????文件????????180??2011-12-22?14:32??wince?C#?讀寫xm
?????文件??????28160??2011-12-22?15:04??wince?C#?讀寫xm
?????文件????????180??2011-12-22?14:32??wince?C#?讀寫xm
?????文件????????383??2009-09-18?09:27??wince?C#?讀寫xm
?????文件???????1453??2009-09-18?09:27??wince?C#?讀寫xm
?????文件???????2373??2009-09-18?09:27??wince?C#?讀寫xm
?????文件???????5618??2009-09-18?09:27??wince?C#?讀寫xm
?????文件???????4202??2009-09-18?09:36??wince?C#?讀寫xm
?????文件????????198??2011-12-22?14:32??wince?C#?讀寫xm
?????文件???????1110??2009-09-18?09:27??wince?C#?讀寫xm
????..A..H.?????17920??2011-12-22?15:19??wince?C#?讀寫xm
?????文件?????????55??2011-12-22?15:20??wince?C#?讀寫xm
?????目錄??????????0??2011-12-27?11:41??wince?C#?讀寫xm
?????目錄??????????0??2011-12-27?11:41??wince?C#?讀寫xm
?????目錄??????????0??2011-12-27?11:41??wince?C#?讀寫xm
?????目錄??????????0??2011-12-27?11:41??wince?C#?讀寫xm
?????目錄??????????0??2011-12-27?11:41??wince?C#?讀寫xm
?????目錄??????????0??2011-12-27?11:41??wince?C#?讀寫xm
?????目錄??????????0??2011-12-27?11:41??wince?C#?讀寫xm
?????目錄??????????0??2011-12-27?11:41??wince?C#?讀寫xm
............此處省略6個文件信息
評論
共有 條評論