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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
DOM模型和LINQ模型對比

在向大家詳細介紹LINQ模型之前,首先讓大家了解下DOM模型,然后全面介紹LINQ模型

DOM模型和LINQ模型

我們知道關(guān)于XML,W3C有一套DOM模型,C#語言有一套在DOM模型下操作XML的類庫。但是在LINQ模型出現(xiàn)以后,微軟又重新做了一套關(guān)于XML的模型,而且操作起來同那套DOM模型沒什么兩樣,但是更加的簡單。

以上是一套新的類庫。其中最核心的類就是XElement,不要看它的層次低,但是絕對是核心。還有一些其他特性與DOM模型不一樣,其中之一就是XAttribute和XNode在同一個層次上,還有就是XDocument不再是必須的。其他不同點可以參考DOM模型自己比較。

下面用代碼對比一下DOM模型和LINQ模型操作XML的區(qū)別:

 
 
 
 
  1. //DOM模型  
  2.  
  3. XmlDocument doc = new XmlDocument();  
  4. XmlElement name = doc.CreateElement("name");  
  5. name.InnerText = "Patrick Hines";  
  6. XmlElement phone1 = doc.CreateElement("phone");  
  7. phone1.SetAttribute("type", "home");  
  8. phone1.InnerText = "206-555-0144";  
  9. XmlElement phone2 = doc.CreateElement("phone");  
  10. phone2.SetAttribute("type", "work");  
  11. phone2.InnerText = "425-555-0145";  
  12. XmlElement street1 = doc.CreateElement("street1");  
  13. street1.InnerText = "123 Main St";  
  14. XmlElement city = doc.CreateElement("city");  
  15. city.InnerText = "Mercer Island";  
  16. XmlElement state = doc.CreateElement("state");  
  17. state.InnerText = "WA";  
  18. XmlElement postal = doc.CreateElement("postal");  
  19. postal.InnerText = "68042";  
  20. XmlElement address = doc.CreateElement("address");  
  21. address.AppendChild(street1);  
  22. address.AppendChild(city);  
  23. address.AppendChild(state);  
  24. address.AppendChild(postal);  
  25. XmlElement contact = doc.CreateElement("contact");  
  26. contact.AppendChild(name);  
  27. contact.AppendChild(phone1);  
  28. contact.AppendChild(phone2);  
  29. contact.AppendChild(address);  
  30. XmlElement contacts = doc.CreateElement("contacts");  
  31. contacts.AppendChild(contact);  
  32. doc.AppendChild(contacts); 
 
 
 
 
  1. //LINQ模型  
  2.  
  3. XElement contacts =  
  4. new XElement("contacts",  
  5. new XElement("contact",  
  6. new XElement("name", "Patrick Hines"),  
  7. new XElement("phone", "206-555-0144",   
  8. new XAttribute("type", "home")),  
  9. new XElement("phone", "425-555-0145",  
  10. new XAttribute("type", "work")),  
  11. new XElement("address",  
  12. new XElement("street1", "123 Main St"),  
  13. new XElement("city", "Mercer Island"),  
  14. new XElement("state", "WA"),  
  15. new XElement("postal", "68042")  
  16. )  
  17. )  
  18. ); 

這里只是很簡單的演示一些操作,至于那些復(fù)雜的操作,只要DOM模型能實現(xiàn)的LINQ模型就一定能實現(xiàn)。插入的時候還可以使用AddAfterThis和AddBeforeThis等方法,提高效率。

【編輯推薦】

  1. LINQ to SQL Table淺談
  2. Linq語句問題的解決方法
  3. Ling to sql更新實體概述
  4. Linq實體繼承簡單描述
  5. Linq Library概述

文章題目:DOM模型和LINQ模型對比
網(wǎng)址分享:http://www.dlmjj.cn/article/cdpgejo.html