Silverlight的应用方法非常广泛。我们可以利用这样的一款多媒体处理工具实现许多功能需求。在这里我们就为大家详细介绍一下有关Silverlight读取XML的相关操作技巧。希望对又需要的朋友有些帮助。#t#
咸丰ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
Silverlight读取XML的例子是为我的试验项目"SLShowCase"做的读取xml的试验.看到园子里的朋友做到仿163幻灯片的demo就提前发上来了.
项目的功能是做案例展示.
ok 首先,先定义xml.
- projects.xml
- < ?xml version="1.0" encoding="utf-8" ?>
- < projects>
- < project id="1" title="nasa.wang
@ cnblogs" category="web" hit="23"
createdate="2008-4-9" converpic=
"null" iscommend="true"
votenum="8" score="10">- < /project>
- < /projects>
在sl中定义类.
- public class project
- {
- public int id { get; set; }
- public string title { get; set; }
- public string category { get; set; }
- public int hit { get; set; }
- public DateTime createdate { get; set; }
- public string converpic { get; set; }
- public bool iscommend { get; set; }
- public int votenum { get; set; }
- public int score { get; set; }
- //public IList< pitem> pitems { get; set; }
- //public IList< pcomment>
pcomments { get; set; }- }
使用WebClient来加载数据.linq来格式化数据.
- public Page()
- {
- InitializeComponent();
- WebClient client = new WebClient();
- client.DownloadStringAsync(new Uri
(HtmlPage.Document.DocumentUri,
"projects.xml"));- client.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler
(client_DownloadStringCompleted);- }
- void client_DownloadStringCompleted
(object sender, DownloadString
CompletedEventArgs e)- {
- XmlReader reader = XmlReader.Create
(new StringReader(e.Result));- XDocument document = XDocument.Load(reader);
- var projects = from f in document.
Descendants("project")- select new project
- {
- id = int.Parse(f.Attribute("id").Value),
- title = f.Attribute("title").Value,
- category = f.Attribute("category").Value,
- hit = int.Parse(f.Attribute("hit").Value),
- createdate = DateTime.Parse(f.
Attribute("createdate").Value),- converpic = f.Attribute("converpic")
.Value,- iscommend = bool.Parse(f.Attribute
("iscommend").Value),- votenum = int.Parse(f.Attribute("votenum").Value),
- score = int.Parse(f.Attribute("score").Value),
- };
- List< project> _projects = new List< project>();
- _projects.AddRange(projects);
- txtStatus.Text ="read success for "
+ _projects[0].title;- }
Silverlight读取XML完毕. ????
新闻名称:Silverlight读取XML相关操作方法
转载源于:http://www.mswzjz.cn/qtweb/news27/109227.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能