av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

LINQToXML類詳細分析

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

LINQ To XML類

下面重點學習三個類:XDocument,XElement,Xattribute

1.LINQ To XML類——XDocument類:表示一個 XML 文檔。XDocument可以包含以下元素:
◆一個 XDeclaration 對象。XDeclaration 使您能夠指定 XML 聲明的相關部分: XML 版本、文檔的編碼,以及 XML 文檔是否是獨立的。
◆一個 XElement 對象。 這是 XML 文檔的根節(jié)點。
◆任意數(shù)目的 XProcessingInstruction 對象。 處理指令將信息傳遞給處理 XML 的應用程序。
◆任意數(shù)目的 XComment 對象。 注釋將與根元素同級。 XComment 對象不能是列表中的第一個參數(shù),因為 XML 文檔以注釋開頭無效。
◆一個用于 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類:表示一個 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類:屬性是與元素關聯(lián)的名稱/值對。 XAttribute 類表示 XML 屬性。

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

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

網(wǎng)站名稱:LINQToXML類詳細分析
標題網(wǎng)址:http://uogjgqi.cn/article/djicicg.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流