偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

DOM模型和LINQ模型對(duì)比

開發(fā) 后端
這里介紹DOM模型和LINQ模型對(duì)比,C#語(yǔ)言有一套在DOM模型下操作XML的類庫(kù)。但是在LINQ模型出現(xiàn)以后,微軟又重新做了一套關(guān)于XML的模型,而且操作起來(lái)同那套DOM模型沒(méi)什么兩樣。

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

DOM模型和LINQ模型

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

DOM模型

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

下面用代碼對(duì)比一下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. ); 

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

【編輯推薦】

  1. LINQ to SQL Table淺談
  2. Linq語(yǔ)句問(wèn)題的解決方法
  3. Ling to sql更新實(shí)體概述
  4. Linq實(shí)體繼承簡(jiǎn)單描述
  5. Linq Library概述
責(zé)任編輯:佚名 來(lái)源: IT168
相關(guān)推薦

2009-09-18 17:17:58

LINQ模型

2010-09-28 09:33:25

DOM模型

2009-09-08 16:20:12

LINQ to SQL

2009-09-15 10:12:37

LINQ To SQL

2010-09-28 10:40:32

HTML DOM

2009-09-18 14:07:51

LINQ to SQL

2022-10-09 15:26:45

人工智能ML機(jī)器學(xué)習(xí)

2010-09-28 10:03:15

DOM文檔對(duì)象模型

2012-04-26 08:29:22

DOM

2010-09-28 09:43:37

DOM文檔對(duì)象模型

2010-09-28 13:24:34

DOM文檔對(duì)象模型

2010-09-28 09:22:34

DOM模型Html

2025-07-03 02:15:00

DOM對(duì)象模型JavaScript

2009-09-14 13:50:35

LINQ編程模型

2009-02-10 09:23:03

DOM模型MSXML

2020-10-15 11:22:34

PyTorchTensorFlow機(jī)器學(xué)習(xí)

2010-09-28 11:03:19

XML DOM

2010-09-28 10:09:35

DOM對(duì)象模型

2010-09-28 09:38:22

DOM模型

2009-05-11 10:40:36

.NETLINQforeach
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)