DataSet和XML

• 在ADO.NET组件中DataSet是其核心组
件之一,它提供了独立于数据源的数据
访问,为了实现这种平台互用性和可伸
缩的数据访问,ADO.NET采用了基于
XML数据的传输格式,XML在这里充当
了至关重要的脚色。
• 当数据传输时,ADO.NET是将DataSet
表述为XML,然后以XML格式传递给其
他组件。
None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Xml;
None.gif
using  System.IO;
None.gif
using  System.Data.SqlClient;
None.gif
namespace  AddsAndXML
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//**//**//// <summary>
InBlock.gif    
/// dsAndXml 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class dsAndXml : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.Button btnView;
InBlock.gif        
protected System.Web.UI.WebControls.ListBox lbItem;
InBlock.gif        
protected System.Web.UI.WebControls.Button btnLoad;
InBlock.gif        
protected System.Web.UI.WebControls.DataGrid dgViewXml;
InBlock.gif        
protected System.Web.UI.WebControls.Button btnBuild;
InBlock.gif    
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
ExpandedSubBlockEnd.gif
        }

InBlock.gif
InBlock.gif        
//从数据库生成DataSet
InBlock.gif
        public DataSet CreateDateSet()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 创建到Sql Server数据库的连接
InBlock.gif
            string strconn="Server=(local);Database=Pubs;uid=sa;pwd=111";
InBlock.gif            SqlConnection conn 
= new SqlConnection ();
InBlock.gif            conn.ConnectionString 
= strconn;
InBlock.gif            conn.Open(); 
InBlock.gif            
// 创建关于Authors表的数据集
InBlock.gif
            string strAuthorsSql = "SELECT * FROM authors";
InBlock.gif            SqlDataAdapter da 
= new SqlDataAdapter(strAuthorsSql,conn);
InBlock.gif            da.SelectCommand.CommandType 
= CommandType.Text;
InBlock.gif            
// 声明DataSet
InBlock.gif
            DataSet ds = new DataSet();
InBlock.gif            da.Fill (ds,
"XMLAuthors");
InBlock.gif            
// 返回DataSet数据集
InBlock.gif
            return ds;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//创建XmlDocument对象
InBlock.gif
        public XmlDocument BuildXml()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
// 声明MemoryStream对象
InBlock.gif
            XmlDocument doc=new XmlDocument();
InBlock.gif            MemoryStream mStrm 
= new MemoryStream ();
InBlock.gif            StreamReader sRead 
= new StreamReader(mStrm); 
InBlock.gif
InBlock.gif            
// 调用CreateDataSet方法把DataSet中的数据输出
InBlock.gif
            CreateDateSet().WriteXml (mStrm,XmlWriteMode.IgnoreSchema);
InBlock.gif
InBlock.gif            
// 从数据流的开始位置进行搜索
InBlock.gif
            mStrm.Seek (0,SeekOrigin.Begin);
InBlock.gif            
// 将数据流加载到XmlDocument
InBlock.gif
            doc.Load (sRead);
InBlock.gif            
return doc; 
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
//创建写入XML文件的方法BuildFile(): 
InBlock.gif
        private void BuildFile()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 要写入文件的路径
InBlock.gif
            string filepath = Server.MapPath("Authors.xml");
InBlock.gif            CreateDateSet().WriteXml(filepath); 
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        Web Form Designer generated code
Web Form Designer generated code#region Web Form Designer generated code
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.btnView.Click += new System.EventHandler(this.btnView_Click);
InBlock.gif            
this.btnBuild.Click += new System.EventHandler(this.btnBuild_Click);
InBlock.gif            
this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private void btnView_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 清除ListBox的所有项
InBlock.gif

InBlock.gif            lbItem.Items.Clear();
InBlock.gif            XmlNodeList ndList 
= BuildXml().GetElementsByTagName("XMLAuthors");
InBlock.gif            
foreach(XmlNode xn in ndList) 
InBlock.gif                lbItem.Items.Add (xn.InnerText); 
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void btnBuild_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            BuildFile();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void btnLoad_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataSet ds 
= new DataSet();
InBlock.gif
InBlock.gif            
string filepath = Server.MapPath("Authors.xml");
InBlock.gif            ds.ReadXml (filepath);
InBlock.gif
InBlock.gif            dgViewXml.DataSource 
= ds;
InBlock.gif
InBlock.gif            dgViewXml.DataMember 
= "XMLAuthors"
InBlock.gif            dgViewXml.DataBind();
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gifXmlDocument类
None.gif• 位于System.Xml名称空间
None.gif• 是XML文档的内存表示
None.gif• 当一个XML文档被载入时,它作为
None.gifXmlNode对象群组的一部分被载入到一树
None.gif型描述中。每个XmlNode对象可以有多个
None.gif子XmlNode对象,但是只能有一个父节点
None.gif    
private   void  btnCreate_Click( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
int nFQ;
InBlock.gif            XmlDocument doc 
= new XmlDocument();
InBlock.gif            XmlAttribute newAtt;
InBlock.gif
InBlock.gif
InBlock.gif            
//定义XML文档头文件
InBlock.gif
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0",null,null);
InBlock.gif            doc.AppendChild(dec);
InBlock.gif            XmlElement docRoot 
= doc.CreateElement("Orders");
InBlock.gif            doc.AppendChild(docRoot);
InBlock.gif
InBlock.gif            
for(int i=0;i<12;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                XmlNode Order 
= doc.CreateElement("Order");
InBlock.gif                newAtt 
= doc.CreateAttribute("Quantity");
InBlock.gif                nFQ 
= 10*+i;
InBlock.gif                newAtt.Value 
= nFQ.ToString();
InBlock.gif                Order.Attributes.Append(newAtt);
InBlock.gif                docRoot.AppendChild(Order);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
//保存XML文档
InBlock.gif
            string strPath = Server.MapPath("OutDocument.XML");
InBlock.gif            doc.Save(strPath);
ExpandedBlockEnd.gif        }

None.gif
None.gif        
private   void  btnRead_Click( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            XmlDocument doc 
= new XmlDocument();
InBlock.gif            XmlElement TempNode;
InBlock.gif            
string strPath = Server.MapPath("OutDocument.XML");
InBlock.gif            doc.Load(strPath);
InBlock.gif            Response.Write(
"文档已经加载!<br>");
InBlock.gif            XmlNodeList xnl
=doc.SelectSingleNode("Orders").ChildNodes;
InBlock.gif 
InBlock.gif            
foreach(XmlNode xn in xnl)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                TempNode 
= (XmlElement)xn;
InBlock.gif                Response.Write(
"Order Quantity:"+TempNode.GetAttribute("Quantity")+"<br>");
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }
XPath
• XPath(XML 路径语言)是用来查询和定位XML
文档里的元素以及文本的一种通用查询方法。
• 许多人将XPath看作Internet的SQL语言。
• XPath语法使用称为表达式的模式。初始化时结
果集中没有任何东西,利用XPath表达式使得出
现在结果集里的节点形成特定的层次结构并符合
一定的条件。
• XPath上下文:是我们将要查询文档的文档树中
一个特定的节点。可以认为是查询的一个起始点。
XPath表达式
• 由位置步组成。它由一个轴、一个节点测
试和可选择的一系列谓词构成。通过使用
反斜杠连接多个位置步形成位置路径,产
生一组节点作为结果。
• /Books/book/title:要求元素Books的子元
素book的所有子元素title。
• /Books/book[@Price<21.99]/title:返回
Books根元素下book子元素中,所有Price
属性值小于21.99的book的所有title子元素
XPath表达式
• 位置步:表达式中由反斜杠分开的每个部
分被称为一个位置步。
• 轴:是与上下文节点相对的文档的一部
分,它定义了一组与当前节点有特定层次
关系的节点。
• 节点测试:可以用来指示位置路径中一组
合法节点的任何表达式。节点测试通过名
字或类型筛选初始结果集。
– child::text():返回所有文本子节点。
• 谓词:true或false的一个表达式。

• 轴心包括:self、child、parent、
descendent、ancestor、attribute、
namespace、following、preceding
• child::Customer:返回当前节点子元素中的
所有Customer元素
• descendent::OrderItem:返回节点名
为”OrderItem“的所有后代
XPath表达式示例
• ./Order将找到当前上下文中名为Order的所有元素
• /Order将找到文档树中根下所有名为Order的元素
• //Order将在文档树的任何地方找到所有名为Order
的元素,不管深度或层次结构
• child::book[attribute::publisher=‘张三’]
• child::book[@publisher=‘张三’]
• descendent::book[count(child::chapter)>5]:用
count函数检索所有chapter大于5的后代book节点
• child::book[start-with(attribute::publisher,’张’)]:使
用start-with函数检索所有publisher属性以’张’开头
的book子节点.
XPath缩略语法
• //代表后代轴
• @代表属性轴
• .代表自己
• ..代表父节点
None.gif private   void  Page_Load( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            XmlDocument XDoc;
InBlock.gif            XmlNodeList XNodes;
InBlock.gif
InBlock.gif            XDoc 
= new XmlDocument();
InBlock.gif            XDoc.Load(Server.MapPath(
"Orders.xml"));
InBlock.gif
InBlock.gif            XNodes 
= XDoc.DocumentElement.SelectNodes("//Customer[starts-with(@Name,'A')]/Order");
InBlock.gif
InBlock.gif            
//以下没有使用缩略语法
InBlock.gif
//            XNodes = XDoc.DocumentElement.SelectNodes("descendant::Customer[start-with(attribute::Name,'A')]/child::Order");
InBlock.gif

InBlock.gif            Response.Write(
"找到 "+XNodes.Count.ToString()+"个节点<br>");
InBlock.gif            
foreach(XmlNode XNode in XNodes)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Response.Write(
"Customer "+XNode.ParentNode.Attributes.GetNamedItem("Name").Value
InBlock.gif                    
+" Ordered  "+XNode.Attributes.GetNamedItem("Quantity").Value
InBlock.gif                    
+" "+XNode.InnerText+"<br>");
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }
DataSet过滤
• Select方法:通过一个过滤字符串来过滤表
中的行
• DataView
Select方法
• 它返回一组符合查询中所指定标准的
DataRow对象。
• 除了给出过滤表达式以外,还可以提供一
个DataRowViewState,以便选择所有不仅
符合给定标准而且还有指定版本(比如添
加、源数据、删除)的行
None.gif private   void  Page_Load( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            DataSet StudentDS 
= new DataSet();
InBlock.gif            StudentDS.ReadXmlSchema(Server.MapPath(
"Students.XSD" ));
InBlock.gif            StudentDS.ReadXml(Server.MapPath(
"Students.XML") );
InBlock.gif            
// Accept changes now so that original data from the XML file
InBlock.gif            
// is considered "original".
InBlock.gif
            StudentDS.AcceptChanges();
InBlock.gif
InBlock.gif            Response.Write(
"GPA小于2的学生有:<br>");
InBlock.gif
InBlock.gif            DataRow[] SelectRows 
= StudentDS.Tables["Student"].Select( "GPA < 2.0" );
InBlock.gif            
for (int i=0; i< SelectRows.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Response.Write( SelectRows[i][
"Name"]+"<br>" );
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            SelectRows 
= StudentDS.Tables["Student"].Select( "Age>16" );
InBlock.gif            Response.Write(
"<br>大于16岁的学生有:<br>");
InBlock.gif
InBlock.gif            
for (int i=0; i<SelectRows.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Response.Write( SelectRows[i][
"Name"]+"<br>" );
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
// now add a new row so we can test out versioning
InBlock.gif            
// selects.
InBlock.gif

InBlock.gif            DataRow NewRow 
= StudentDS.Tables["Student"].NewRow();
InBlock.gif            NewRow[
"ID"= 8;
InBlock.gif            NewRow[
"Name"= "The New Kid";
InBlock.gif            NewRow[
"Age"= 17;
InBlock.gif            NewRow[
"GPA"= 3.99;
InBlock.gif            NewRow[
"LockerCombination"= "5-9-30";
InBlock.gif            StudentDS.Tables[
"Student"].Rows.Add( NewRow );
InBlock.gif
InBlock.gif            NewRow 
= StudentDS.Tables["Student"].NewRow();
InBlock.gif            NewRow[
"ID"= 9;
InBlock.gif            NewRow[
"Name"= "Girl Genius";
InBlock.gif            NewRow[
"Age"= 12;
InBlock.gif            NewRow[
"GPA"= 4.15;
InBlock.gif            NewRow[
"LockerCombination"= "3-2-1";
InBlock.gif            StudentDS.Tables[
"Student"].Rows.Add( NewRow );
InBlock.gif
InBlock.gif            
// important here not to AcceptChanges, so the DataSet still knows
InBlock.gif            
// which rows are "new".
InBlock.gif

InBlock.gif            Response.Write(
"<br>新增并且年龄大于16的学生:<br>");
InBlock.gif            Console.WriteLine(
"-------------------------------------------");
InBlock.gif            SelectRows 
= StudentDS.Tables["Student"].Select("Age > 16""", DataViewRowState.Added );
InBlock.gif            
for (int i=0; i<SelectRows.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Response.Write( SelectRows[i][
"Name"]+"<br>" );
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }
DataView
• 是一个给定DataTable的可绑定的定制视图。
• 通过定制视图,我们可以控制视图允许用
户看什么DataViewRowState
• 也可以提供筛选表达式,以控制哪些行对
于视图来说是可以访问的
• 除了允许用户查看特定数据外,也可以通
过视图修改原始表中的数据,只要修改符
合视图的约束。
None.gif private   void  Page_Load( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            DataSet StudentDS 
= new DataSet();
InBlock.gif            
//StudentDS.ReadXmlSchema( Server.MapPath("Students.XSD" ));
InBlock.gif
            StudentDS.ReadXml(Server.MapPath("Students.XML") );
InBlock.gif            
// again, accept the changes so the dataset has an "original" state.
InBlock.gif
            StudentDS.AcceptChanges();
InBlock.gif
InBlock.gif            DataView AddedStudents 
= new DataView( StudentDS.Tables["Student"] );
InBlock.gif            AddedStudents.RowStateFilter 
= DataViewRowState.Added;
InBlock.gif    
InBlock.gif            PrintStudents(AddedStudents, 
"新添加的学生列表:");
InBlock.gif    
InBlock.gif            DataView Prodigies 
= new DataView( StudentDS.Tables["Student"] );
InBlock.gif            Prodigies.RowFilter 
= "(GPA > 3.90) AND (Age < 15)";
InBlock.gif
InBlock.gif            PrintStudents( Prodigies, 
"优秀学生列表:");
InBlock.gif
InBlock.gif            
// now modify the original table (not the views).
InBlock.gif
            DataRow NewRow = StudentDS.Tables["Student"].NewRow();
InBlock.gif            NewRow[
"ID"= 8;
InBlock.gif            NewRow[
"Name"= "The New Kid";
InBlock.gif            NewRow[
"Age"= 17;
InBlock.gif            NewRow[
"GPA"= 3.99;
InBlock.gif            NewRow[
"LockerCombination"= "5-9-30";
InBlock.gif            StudentDS.Tables[
"Student"].Rows.Add( NewRow );
InBlock.gif
InBlock.gif            NewRow 
= StudentDS.Tables["Student"].NewRow();
InBlock.gif            NewRow[
"ID"= 9;
InBlock.gif            NewRow[
"Name"= "Girl Genius";
InBlock.gif            NewRow[
"Age"= 12;
InBlock.gif            NewRow[
"GPA"= 4.15;
InBlock.gif            NewRow[
"LockerCombination"= "3-2-1";
InBlock.gif            StudentDS.Tables[
"Student"].Rows.Add( NewRow );
InBlock.gif
InBlock.gif            PrintStudents( AddedStudents, 
"添加后的学生列表(已经更新)");
InBlock.gif            PrintStudents( Prodigies, 
"优秀学生列表(已经更新)");
InBlock.gif
ExpandedBlockEnd.gif        }

None.gif        
private    void  PrintStudents(DataView dv,  string  Caption)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            Response.Write(
"<br>"+Caption);
InBlock.gif            
for (int i=0; i<dv.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Response.Write(
"<br>"+dv[i]["Name"]);
ExpandedSubBlockEnd.gif            }

InBlock.gif            Response.Write(
"<br>"+dv.Count.ToString()+"个学生");
ExpandedBlockEnd.gif        }

使用XmlDataDocument
• 失真:
– 当DataSet已有一个模式但不是从文档推出来
的模式时,它将只载入模式定义的数据。如果
修改DataSet然后保存到XML,则保存后的
XML不会含有模式以外的属性。
– 另外,字符、格式化字符和空格-它们可能是
原始文档中所需要的或是有意义的-都不会在
DataSet生成的文档中出现

None.gif    private   void  Page_Load( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            DataSet myDS 
= new DataSet();
InBlock.gif            myDS.ReadXmlSchema(Server.MapPath(
"Books.xsd"));
InBlock.gif            myDS.ReadXml(Server.MapPath(
"Books.xml"));
InBlock.gif
InBlock.gif            myDS.WriteXml(Server.MapPath(
"Books_After.XML"));
ExpandedBlockEnd.gif        }

None.gif

XmlDataDocument
• XmlDataDocument允许通过DataSet
来存取、检索和操作结构化的XML数
据。
• XmlDataDocument将保护正与
DataSet结合的XML文档的保真度
• XmlDataDocument与DataSet同步工
作,当一个对象有所改变时,该改变
能被及时地通知给其他对象。

None.gif   private   void  Page_Load( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            DataSet DSStudentClasses 
= new DataSet();
InBlock.gif            XmlNode tmpNode;
InBlock.gif    
InBlock.gif            DSStudentClasses.ReadXmlSchema( Server.MapPath(
"StudentClasses.XSD" ));
InBlock.gif            XmlDataDocument XDocStudents 
= new XmlDataDocument( DSStudentClasses );
InBlock.gif            XDocStudents.Load(Server.MapPath( 
"Students.XML") );
InBlock.gif
InBlock.gif            Response.Write(
"Students in DataSet:");
InBlock.gif            
foreach (DataRow _Row in DSStudentClasses.Tables["Student"].Rows )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Response.Write(_Row[
"Name"]+":"+_Row["GPA"]);
InBlock.gif                tmpNode 
= XDocStudents.GetElementFromRow( _Row );
InBlock.gif                
//XmlElement TempNode = (XmlElement)tmpNode;
InBlock.gif
                Response.Write("<br>Locker Combination (from XML, not DataSet): "+tmpNode.SelectSingleNode("LockerCombination"));
InBlock.gif                
//LockerCombination不在DataSet中,所以当下面取消注释时,会报错。
InBlock.gif                
//Response.Write("<br>Locker Combination (from DS):"+ _Row["LockerCombination"] );
InBlock.gif
                foreach (DataRow _Class in _Row.GetChildRows("StudentClasses") )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Response.Write(
"<br>"+_Class["Title"] );
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

 

使用XSL和XSLT转换XML
• XSL:扩展样式表语言,可以通过它来把
XML转换为其他的文本格式
• XSL转换包括发现或者选择一个模式匹配,
通过使用XPath选择一个结果集,然后对结
果集中的每一项,为这些匹配定义结果输
出。
• XSL是一个功能强大的工具,可以把XML转
换成任何你想要的格式。
/Files/cmzzlh/08UseXSLT.rar

from: http://cmzzlh.cnblogs.com/articles/419766.html
other:
http://hi.baidu.com/fumychina/blog/item/adc3bede45859e58ccbf1ab6.html
http://www.window07.com/dev/web/net/2006-3-3/k73431.htm


None.gif private   void  Page_Load( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            XslTransform xslt 
= new XslTransform();
InBlock.gif            xslt.Load(Server.MapPath( 
"StudentsToHTML.xsl") );
InBlock.gif
InBlock.gif            XPathDocument XDoc 
= new XPathDocument(Server.MapPath( "Students.XML" ));
InBlock.gif            XmlWriter writer 
= new XmlTextWriter( Server.MapPath("Students.HTML"), System.Text.Encoding.UTF8 );
InBlock.gif            xslt.Transform( XDoc, 
null, writer );
InBlock.gif
ExpandedBlockEnd.gif        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值