Tag:开源, 源码, 控件, 控件开发, 皮肤, Skin , MVC , WCF , Remoting , AJAX ,
JQuery , Flex , Silverlight , SQL Server , 设计模式, 框架, 正则, Web
服务 , 数据库,
PetShop , WordPress , Silverlight
读取 *.XML
数据
%
热门搜索:控件美化winform 控件开发源码下载socket asp.net 控件框架开源源码窗体
换肤skin
您的位置:>>首页>>.Net 博文>>Silverlight 读取*.XML 数据
Silverlight 读取*.XML 数据
2009-11-13 来自:CSDN 博客字体大小:【大中小】
摘要:本文介绍 Silverlight 读取*.XML 数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Text;
namespace SLshaw
{
%%% public partial class MainPage : UserControl
请输入关键字
%%% {
%%%%%%% public MainPage()
%%%%%%% {
%%%%%%%%%%% InitializeComponent();
%%%%%%% }
%%%%%%% private void btnXML_Click(object sender, RoutedEventArgs e)
%%%%%%% {
%%%%%%%%%%% string Xpath = @"shadowinswf.xml";
%%%%%%%%%%% StringBuilder sb = new StringBuilder();
%%%%%%%%%%% using (XmlReader reader = XmlReader.Create(Xpath))
%%%%%%%%%%% {
%%%%%%%%%%%%%%% while (reader.Read())
%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%% if (reader.IsStartElement() && "window" ==
reader.LocalName.ToLower())
%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%% sb.Append("state= " + reader.GetAttribute("state".ToLower())
+ "\r\n");
%%%%%%%%%%%%%%%%%%%%%%% using (XmlReader itemreader = reader.ReadSubtree())
%%%%%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%%%%%% while (itemreader.Read())
%%%%%%%%%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if (itemreader.IsStartElement())
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if ("title" == itemreader.LocalName.ToLower())
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sb.Append("title: " +
itemreader.ReadElementContentAsString() + "\r\n");
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% else if ("os" == itemreader.LocalName.ToLower())
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sb.Append("os: " +
itemreader.ReadElementContentAsString() + "\r\n");
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% else if ("description" ==
itemreader.LocalName.ToLower())
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sb.Append("description: " +
itemreader.ReadElementContentAsString() + "\r\n");
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% else if ("img" == itemreader.LocalName.ToLower())
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sb.Append("img: " +
itemreader.ReadElementContentAsString() + "\r\n");
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% else if ("uuid" == itemreader.LocalName.ToLower())
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% {
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sb.Append("uuid: " +
itemreader.ReadElementContentAsString());
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%%%%%%%%%% this.txtXML.Text = sb.ToString();
%%%%%%%%%%%%%%%%%%% }
%%%%%%%%%%%%%%% }
%%%%%%%%%%% }
%%%%%%% }%%%%
%%% }
}
参考文章:
【http://www.lan27.com/Article/200705/946.htm】
【http://msdn.microsoft.com/en-us/library/cc189040(VS.95).aspx】
【http://msdn.microsoft.com/zh-cn/vstudio/cc838250(VS.95).aspx】
本章中的 QuickStart 示例演示如何使用 Silverlight 中的.NET Framework 子集部分来
得到远程的XML 内容, 使用 XmlReader 来读入内容, 以及使用 StringBuilder 和
XmlWriter 来将内容输出到 XAML 中.
运行查看想要在基于 Silverlight 的应用程序中做到以上的功能,你需要准备以下步骤:
- 1
- 2
- 3
前往页