日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
LINQToXML類詳細(xì)分析

本文向大家介紹LINQ To XML類,可能好多人還不了解LINQ To XML類,沒(méi)有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。

LINQ To XML類

下面重點(diǎn)學(xué)習(xí)三個(gè)類:XDocument,XElement,Xattribute

1.LINQ To XML類——XDocument類:表示一個(gè) XML 文檔。XDocument可以包含以下元素:
◆一個(gè) XDeclaration 對(duì)象。XDeclaration 使您能夠指定 XML 聲明的相關(guān)部分: XML 版本、文檔的編碼,以及 XML 文檔是否是獨(dú)立的。
◆一個(gè) XElement 對(duì)象。 這是 XML 文檔的根節(jié)點(diǎn)。
◆任意數(shù)目的 XProcessingInstruction 對(duì)象。 處理指令將信息傳遞給處理 XML 的應(yīng)用程序。
◆任意數(shù)目的 XComment 對(duì)象。 注釋將與根元素同級(jí)。 XComment 對(duì)象不能是列表中的第一個(gè)參數(shù),因?yàn)?XML 文檔以注釋開頭無(wú)效。
◆一個(gè)用于 DTD 的 XDocumentType。

用XDocument創(chuàng)建XML文件

 
 
 
  1. XDocument d = new XDocument( new XDeclaration("1.0", "utf-8", "true"),  
  2. new XComment("This is a comment."),  
  3. new XProcessingInstruction("xml-stylesheet", 
    "href='mystyle.css' title='Compact' type='text/css'"),  
  4. new XElement("Pubs",  
  5. new XElement("Book",  
  6. new XElement("Title", "Artifacts of Roman Civilization"),  
  7. new XElement("Author", "Moreno, Jordao")  
  8. )   
  9. )   
  10. );  
  11. Console.WriteLine(d.Declaration );  
  12. Console.WriteLine(d);  
  13. //XML文件  
  14.  version="1.0" encoding="utf-8" standalone="true"?> 
  15.  
  16.  href='mystyle.css' title='Compact' type='text/css'?> 
  17.  
  18.  
  19. </strong>Artifacts of Roman Civilization<strong> 
  20. Moreno, Jordao 
  21.  
  22.  

2.LINQ To XML類——XElement類:表示一個(gè) XML 元素。XDocument 可以包含以下元素:
◆Xelement
◆Xcomment
◆XprocessingInstruction
◆XText

用XElement創(chuàng)建XML文件

 
 
 
  1. XElement xml1 = new XElement("Root",  
  2. new XElement("Node1", 1),  
  3. new XElement("Node2", 2),  
  4. new XElement("Node3", 3),  
  5. new XElement("Node4", 4),  
  6. new XElement("Node5", 5),  
  7. new XElement("Node6", 6)  
  8. );  
  9. XElement xml2 = new XElement("Root",  
  10. from el in xml1.Elements()  
  11. where ((int)el >= 3 && (int)el <= 5)  
  12. select el  
  13. );  
  14. Console.WriteLine(xml2);  
  15. //XML文件  
  16. <Root> 
  17. 3 
  18. 4 
  19. 5 
  20.  

3.LINQ To XML類——XAttribute類:屬性是與元素關(guān)聯(lián)的名稱/值對(duì)。 XAttribute 類表示 XML 屬性。

屬性與元素之間有些區(qū)別。XAttribute 對(duì)象不是 XML 樹中的節(jié)點(diǎn)。 它們是與 XML 元素關(guān)聯(lián)的名稱/值對(duì)。 與文檔對(duì)象模型 (DOM) 相比,這更加貼切地反映了 XML 結(jié)構(gòu)。 雖然 XAttribute 對(duì)象實(shí)際上不是 XML 樹的節(jié)點(diǎn),但使用 XAttribute 對(duì)象與使用 XElement 對(duì)象非常相似。

 
 
 
  1. XElement phone = new XElement("Phone",  
  2. new XAttribute("Type", "Home"),  
  3. "555-555-5555");  
  4. Console.WriteLine(phone); 

網(wǎng)頁(yè)題目:LINQToXML類詳細(xì)分析
文章來(lái)源:http://www.dlmjj.cn/article/djicicg.html