




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、來自來自 中國最大的資料庫下載中國最大的資料庫下載 在.NET 中處理 XML來自來自 中國最大的資料庫下載中國最大的資料庫下載2回顧q 跟蹤是ASP.NET 引入的新功能,只需對(duì)頁面和應(yīng)用程序啟用此功能,就可以查看有關(guān)單個(gè)ASP.NET 頁請求的診斷信息q 頁面級(jí)跟蹤具有一個(gè)稱為 TraceMode 的屬性,此屬性接受 SortByCategory 或 SortByTime 屬性值,以決定如何顯示輸出結(jié)果q 應(yīng)用程序級(jí)跟蹤將啟動(dòng)對(duì)整個(gè)應(yīng)用程序的跟蹤。需要在web.config配置文件中進(jìn)行設(shè)置q 緩存是一項(xiàng)在計(jì)算中廣泛用來提高性能的技術(shù),它將訪問頻率高的數(shù)據(jù)或構(gòu)造成本高的數(shù)據(jù)保留在內(nèi)存中q
2、輸出緩存將緩存整個(gè)頁面,數(shù)據(jù)緩存將設(shè)置內(nèi)存變量緩存q 使用 VS.NET的“Web安裝項(xiàng)目”可以將應(yīng)用程序打包成易于部署的形式來自來自 中國最大的資料庫下載中國最大的資料庫下載3目標(biāo)q 理解XMLDocument 結(jié)構(gòu)q 使用 XML 命名空間中的 XMLDocument 對(duì)象q 使用 XMLReader 和 XMLWriter 對(duì)象q 使用 XMLValidatingReaderq 填充 XML 文件中的數(shù)據(jù)集q 使用數(shù)據(jù)集創(chuàng)建 XML 文檔來自來自 中國最大的資料庫下載中國最大的資料庫下載4XML 文檔結(jié)構(gòu)標(biāo)準(zhǔn) 基于文本的數(shù)據(jù)標(biāo)準(zhǔn)通信XML用于定義語義標(biāo)簽的規(guī)則集合將文檔分解為多個(gè)部分標(biāo)識(shí)
3、文檔各部分元數(shù)據(jù)是定義用于定義其他特定于域的語義和結(jié)構(gòu)化標(biāo)記語言的語法用途來自來自 中國最大的資料庫下載中國最大的資料庫下載5組織 XML 數(shù)據(jù)標(biāo)識(shí)使用的版本 演示根元素的示例代碼. Phonebook 元素具有開始標(biāo)簽 和結(jié)束標(biāo)簽1998 具有子元素 的 Phonebook 元素來自來自 中國最大的資料庫下載中國最大的資料庫下載6System.Xml命名空間q System.Xml命名空間包含了處理Xml的類,以下是經(jīng)常用到的類qXmlTextReader 類提供對(duì) XML 數(shù)據(jù)的快速、非高速緩存的只進(jìn)讀訪問qXmlValidatingReader 類提供 DTD、XDR 和 XSD Sch
4、ema 驗(yàn)證qXmlTextWriter 類提供一種生成 XML 的快速只進(jìn)方法qXmlDataDocument 類提供 XmlDocument 的實(shí)現(xiàn),此 XmlDocument 可以與數(shù)據(jù)集關(guān)聯(lián)。可以通過數(shù)據(jù)集的關(guān)系表示或 XmlDataDocument 的樹表示,來同時(shí)查看和操作結(jié)構(gòu)化的 XMLqXPathNavigator 類提供 W3C XPath 1.0 數(shù)據(jù)模型,而不是用于導(dǎo)航的光標(biāo)樣式模型的存儲(chǔ)qXslTransform 類是一個(gè) W3C XSLT 1.0 規(guī)范兼容的 XSLT 處理器,用于轉(zhuǎn)換 XML 文檔qXmlSchema 對(duì)象模型類提供一組直接反映 W3C XSD 規(guī)范
5、的可導(dǎo)航類。這些類支持在程序中創(chuàng)建 XSD Schema來自來自 中國最大的資料庫下載中國最大的資料庫下載7XMLDocument 對(duì)象提供了對(duì)讀取、寫入和操作 XML 文檔的支持執(zhí)行任務(wù)(如加載和保存文檔) 包括 Load()、 LoadXML() 和 Save() 用于訪問文檔中的所有節(jié)點(diǎn)+來自來自 中國最大的資料庫下載中國最大的資料庫下載8XML 節(jié)點(diǎn)類型DOM 節(jié)點(diǎn)類型節(jié)點(diǎn)類型 說明說明 文檔(Document) 此節(jié)點(diǎn)類型是所有節(jié)點(diǎn)的容器,也稱為文檔的根根元素(DocumentElement)XmlDocument的根元素,一個(gè)Document只有一個(gè)DocumentElement文
6、檔類型(DocumentType)此節(jié)點(diǎn)類型表示 節(jié)點(diǎn)元素(XmlElement)此節(jié)點(diǎn)類型表示元素節(jié)點(diǎn) 屬性(XmlAttribute)此節(jié)點(diǎn)類型表示元素節(jié)點(diǎn)的屬性注釋(XmlComment)此節(jié)點(diǎn)類型表示注釋節(jié)點(diǎn)文本(XmlText)此節(jié)點(diǎn)類型表示屬于特定節(jié)點(diǎn)或?qū)傩缘奈谋緛碜詠碜?中國最大的資料庫下載中國最大的資料庫下載9加載 XML 文檔 3-1 將 XML 文檔加載到變量中Load( ) 方法如果不能解析或訪問 URL從指定位置加載 XML 文檔返回錯(cuò)誤,并將文檔對(duì)象的 documentElement 屬性設(shè)置為 null來自來自 中國最大的資料庫下載中國最大的資料庫下載10加載 XM
7、L 文檔 3-2 加菲爾德 5555555 紐約 26/10/1978 邁克 6666666 紐約 12/02/1978private void Page_Load(object sender, System.EventArgs e)XmlDocument MyPhone = new XmlDocument();MyPhone.Load(C:InetpubwwwrootaspexCH12phone.xml);lblXmlData.Text = MyPhone.InnerXml.ToString();來自來自 中國最大的資料庫下載中國最大的資料庫下載11加載 XML 文檔 3-3LoadXML(
8、) 方法使用提供的字符串加載 XML 文檔加載成功則返回 true 加載失敗則返回 false,并將文檔對(duì)象的 documentElement 屬性設(shè)置為 nullXmlDocument MyPhone = new XmlDocument();string xmlString = + 加菲爾德 + 5555555 + 北京紐約 + 26/10/1978 + 邁克 + 6666666 + 紐約 + 12/02/1978+ ;MyPhone.LoadXml( xmlString );來自來自 中國最大的資料庫下載中國最大的資料庫下載12獲取節(jié)點(diǎn)和節(jié)點(diǎn)屬性節(jié)點(diǎn)屬性節(jié)點(diǎn)屬性說明說明 HasChildN
9、odes屬性繼承自XmlNode,如果此節(jié)點(diǎn)具有子節(jié)點(diǎn),則此屬性為 TrueChildNodes屬性繼承自XmlNode,所有子節(jié)點(diǎn)的集合(NodeList)InnerXml屬性節(jié)點(diǎn)和其子節(jié)點(diǎn)的串聯(lián)值ParentNode 屬性獲取該節(jié)點(diǎn)的父節(jié)點(diǎn),沒有父節(jié)點(diǎn)則返回Null值InnerText屬性該節(jié)點(diǎn)的字節(jié)點(diǎn)標(biāo)記OuterXml屬性該節(jié)點(diǎn)和其子節(jié)點(diǎn)的標(biāo)記NodeType屬性返回一個(gè)XmlNodeType枚舉類型的值,這個(gè)枚舉可選項(xiàng)有Text、Attrbute、Element、Entity等Value屬性根據(jù)節(jié)點(diǎn)類型(NodeType)返回值:Text返回文本的內(nèi)容、Attribute返回屬性的值
10、、Element返回Null、Entity返回Null等XmlDocument MyPhone = new XmlDocument();MyPhone.Load (Server.MapPath (“phone.xml);/獲取根元素XmlElement root = MyPhone.DocumentElement;XmlElement phone = root.ChildNodes0;獲取節(jié)點(diǎn)節(jié)點(diǎn)屬性來自來自 中國最大的資料庫下載中國最大的資料庫下載13使用 Save 方法編寫 XML 數(shù)據(jù)XmlDocument MyPhone = new XmlDocument();MyPhone.Load
11、(Server.MapPath(phone.xml);XmlElement newFriendsName = MyPhone.CreateElement( Name );newFriendsName.InnerText = 斯坦利;MyPhone.DocumentElement.InsertAfter( newFriendsName, MyPhone.DocumentElement.LastChild );XmlElement newFriendsNumber = MyPhone.CreateElement(Number);newFriendsNumber.InnerText = 777777
12、7;MyPhone.DocumentElement.InsertAfter( newFriendsNumber, MyPhone.DocumentElement.LastChild );XmlElement newFriendsCity = MyPhone.CreateElement(City);newFriendsCity.InnerText = 加利福尼亞;MyPhone.DocumentElement.InsertAfter( newFriendsCity, MyPhone.DocumentElement.LastChild);XmlElement newFriendsDOB = MyP
13、hone.CreateElement( DateOfBirth );newFriendsDOB.InnerText = 12/06/1984;MyPhone.DocumentElement.InsertAfter( newFriendsDOB, MyPhone.DocumentElement.LastChild );MyPhone.Save(Server.MapPath(phone1.xml);Response.Write(數(shù)據(jù)已寫入!單擊“加載”查看 Phone.xml);輸出結(jié)果來自來自 中國最大的資料庫下載中國最大的資料庫下載14從 XML 文檔中讀取節(jié)點(diǎn) 2-1 從從 XML 文檔中讀
14、取節(jié)點(diǎn)文檔中讀取節(jié)點(diǎn)XmlReader提供對(duì) XML 數(shù)據(jù)流的快速訪問另一個(gè)派生類是 XmlValidatingReader(讀取 XML 數(shù)據(jù),并支持 DTD 和 Schema 驗(yàn)證)由用于讀取基于文本的 XML 文件的 XmlTextReader 類實(shí)現(xiàn)一個(gè)抽象類用于確定各種因素(如節(jié)點(diǎn)的深度)來自來自 中國最大的資料庫下載中國最大的資料庫下載15從 XML 文檔中讀取節(jié)點(diǎn) 2-2 using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Xml;usin
15、g System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls; namespace CH12 public class XMLReaderDemo : System.Web.UI.Page protected System.Web.UI.WebControls.Label lblRecords; private void Page_Load(object sen
16、der, System.EventArgs e) string fileName = Server.MapPath (“Phone.xml “); XmlTextReader objXmlTextReader = new XmlTextReader(fileName); while(objXmlTextReader.Read() if (objXmlTextReader.NodeType = XmlNodeType.Element) if (objXmlTextReader.LocalName.Equals(Name) | objXmlTextReader.LocalName.Equals (
17、Number) lblRecords.Text += objXmlTextReader.ReadString() + t; 來自來自 中國最大的資料庫下載中國最大的資料庫下載16在 XML 文檔中寫入節(jié)點(diǎn) 2-1在在 XML 文檔中寫入節(jié)點(diǎn)文檔中寫入節(jié)點(diǎn)XmlWriterXML TextWriter 類派生自該類一個(gè)抽象類幫助創(chuàng)建 XML 流并將數(shù)據(jù)寫入到格式良好的 XML 文檔來自來自 中國最大的資料庫下載中國最大的資料庫下載17在 XML 文檔中寫入節(jié)點(diǎn) 2-2using System;using System.Collections;using System.ComponentModel
18、;using System.Data;using System.Xml;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls; namespace CH12 public class XmlWriterDemo : System.Web.UI.Page private void Page_Load(object sender, System.Ev
19、entArgs e) string FileName = C:InetpubwwwrootaspexCH12phone.xml; XmlTextWriter objXmlTextWriter = new XmlTextWriter( FileName, null); objXmlTextWriter.Formatting = Formatting.Indented; objXmlTextWriter.Indentation= 6; objXmlTextWriter.WriteStartDocument(); objXmlTextWriter.WriteStartElement(, PhoneB
20、ook, ); objXmlTextWriter.WriteStartElement(, Name, ); objXmlTextWriter.WriteString(“加菲爾德); objXmlTextWriter.WriteEndElement(); objXmlTextWriter.WriteStartElement(, Number, ); objXmlTextWriter.WriteString(5555555); objXmlTextWriter.WriteEndElement(); objXmlTextWriter.WriteStartElement(, City, ); objX
21、mlTextWriter.WriteString(“紐約); objXmlTextWriter.WriteEndElement(); objXmlTextWriter.WriteStartElement(, DateOfBirth, ); objXmlTextWriter.WriteString(26/10/1978); objXmlTextWriter.WriteEndElement(); objXmlTextWriter.WriteEndElement(); objXmlTextWriter.WriteEndDocument(); objXmlTextWriter.Flush(); obj
22、XmlTextWriter.Close(); 輸出結(jié)果來自來自 中國最大的資料庫下載中國最大的資料庫下載18使用XML驗(yàn)證讀取器驗(yàn)證XML數(shù)據(jù)屬性值屬性值 說明說明 DTD 根據(jù) DTD 規(guī)則驗(yàn)證文檔Schema 根據(jù) XSD Schema 驗(yàn)證文檔XDR 根據(jù) XDR Schema 驗(yàn)證文檔None 不需要驗(yàn)證Auto 自動(dòng)檢測基于文檔中聲明的驗(yàn)證類型來自來自 中國最大的資料庫下載中國最大的資料庫下載19XML 和數(shù)據(jù)集 數(shù)據(jù)集數(shù)據(jù)集存儲(chǔ)存儲(chǔ) XML 數(shù)據(jù),而不數(shù)據(jù),而不會(huì)引發(fā)任何錯(cuò)誤會(huì)引發(fā)任何錯(cuò)誤導(dǎo)入導(dǎo)入 System.IO 數(shù)據(jù)以數(shù)據(jù)以讀取讀取 XML 數(shù)據(jù)數(shù)據(jù) 列的值 列的值 列的值
23、列的值 數(shù)據(jù)集讀取以下格式的數(shù)據(jù):數(shù)據(jù)集讀取以下格式的數(shù)據(jù):來自來自 中國最大的資料庫下載中國最大的資料庫下載20使用 ReadXml 方法讀取 XML 數(shù)據(jù) 2-1 FileStream myfs = new FileStream(Server.MapPath(xmldatagrid.xml),FileMode.Open, FileAccess.Read);如何打開 XML 文件打開文件之后,定義一個(gè) StreamReader并把 FileStream傳入StreamReader myreader = new StreamReader(myfs);數(shù)據(jù)集讀取 StreamReader. Re
24、adXml() 方法中的 XML 數(shù)據(jù)DataSet myds = new DataSet();myds.ReadXml(myreader);需要將 XML 數(shù)據(jù)綁定到數(shù)據(jù)集DataView mySource = new DataView(myds.Tables0);dbgMyGrid.DataSource = mySource;dbgMyGrid.DataBind();來自來自 中國最大的資料庫下載中國最大的資料庫下載21使用 ReadXml 方法讀取 XML 數(shù)據(jù) .Net 開發(fā)者 精彩站點(diǎn) 學(xué)習(xí) XML 與 ASP.NET Microsoft ASP.NET 官方網(wǎng)站 using Sys
25、tem;using System.Collections;using System.ComponentModel;using System.IO;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace CH12 public class ReadXml : System.Web.UI.Page
26、 protected System.Web.UI.WebControls.Label lblTableName;protected System.Web.UI.WebControls.DataGrid dgMyGrid;private void Page_Load(object sender, System.EventArgs e) DataSet myds = new DataSet(); FileStream myfs = new FileStream(Server.MapPath (xmldatagrid.xml),FileMode.Open, FileAccess.Read); Str
27、eamReader myreader = new StreamReader(myfs);myds.ReadXml(myreader);myfs.Close();DataView mySource = new DataView(myds.Tables0);blTableName.Text = lblTableName.Text+mySource.Table.TableName;dgMyGrid.DataSource = mySource;dgMyGrid.DataBind(); 來自來自 中國最大的資料庫下載中國最大的資料庫下載22使用 WriteXML 方法寫入 XML 數(shù)據(jù)using Sys
28、tem;using System.Collections;using System.ComponentModel;using System.Data;using System.Data.SqlClient; using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace CH12 public class Writexml : System.Web.UI.Page
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 雞西市重點(diǎn)中學(xué)2025屆校高三第五次月考物理試題含解析
- 南開大學(xué)濱海學(xué)院《體育休閑娛樂導(dǎo)論》2023-2024學(xué)年第二學(xué)期期末試卷
- 工程質(zhì)量控制中的風(fēng)險(xiǎn)識(shí)別與應(yīng)對(duì)策略
- 第8課 北宋的政治 教案2024-2025學(xué)年七年級(jí)歷史下冊新課標(biāo)
- 白領(lǐng)上班背包使用習(xí)慣問卷
- 金灣區(qū)溫室大棚施工方案
- 襄陽移動(dòng)木屋施工方案
- 燃燒器改造施工方案
- 噴灰漆施工方案
- 臨時(shí)用戶供電施工方案
- 2025年海南保亭縣事業(yè)單位招聘綜合歷年高頻重點(diǎn)模擬試卷提升(共500題附帶答案詳解)
- 污水處理設(shè)施運(yùn)維服務(wù)投標(biāo)方案(技術(shù)標(biāo))
- 2024年蘇州高博軟件技術(shù)職業(yè)學(xué)院高職單招職業(yè)適應(yīng)性測試歷年參考題庫含答案解析
- 紀(jì)念抗日戰(zhàn)爭暨世界反法西斯戰(zhàn)爭勝利70周年主題班會(huì) 課件
- AB變頻器使用說明書
- 新疆維吾爾自治區(qū)和田地區(qū)各縣區(qū)鄉(xiāng)鎮(zhèn)行政村村莊村名居民村民委員會(huì)明細(xì)及行政區(qū)劃代碼
- DB13-T2355-2016蒸壓加氣混凝土砌塊專用砂漿
- 【課件】時(shí)代與變革-為人生而藝術(shù) 課件高中美術(shù)人美版(2019)美術(shù)鑒賞
- DB44∕T 876-2011 物業(yè)服務(wù) 會(huì)務(wù)服務(wù)規(guī)范
- 橫河氧量變送器標(biāo)定及檢修
- ArcGIS應(yīng)用基礎(chǔ)培訓(xùn)(共98張)
評(píng)論
0/150
提交評(píng)論