Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the difference between DOM model and LINQ model?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is the difference between DOM model and LINQ model". In daily operation, I believe many people have doubts about the difference between DOM model and LINQ model. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "what's the difference between DOM model and LINQ model"! Next, please follow the editor to study!

DOM model and LINQ model

We know that there is a set of DOM models for XML,W3C, and the C # language has a set of class libraries for operating XML under the DOM model. But after the emergence of the LINQ model, Microsoft made a new set of XML model, and the operation is no different from that DOM model, but more simple.

This is a new set of class libraries. The core class is XElement, although its level is low, but it is definitely the core. There are other features that are different from the DOM model, one of which is that XAttribute and XNode are at the same level, and that XDocument is no longer necessary. Other differences can be compared by referring to the DOM model.

Let's compare the difference between the DOM model and the LINQ model for manipulating XML in code:

/ DOM model XmlDocument doc = new XmlDocument (); XmlElement name = doc.CreateElement ("name"); name.InnerText = "Patrick Hines"; XmlElement phone1 = doc.CreateElement ("phone"); phone1.SetAttribute ("type", "home"); phone1.InnerText = "20655-0144"; XmlElement phone2 = doc.CreateElement ("phone"); phone2.SetAttribute ("type", "work"); phone2.InnerText = "425555-0145"; XmlElement street1 = doc.CreateElement ("street1") Street1.InnerText = "123Main St"; XmlElement city = doc.CreateElement ("city"); city.InnerText = "Mercer Island"; XmlElement state = doc.CreateElement ("state"); state.InnerText = "WA"; XmlElement postal = doc.CreateElement ("postal"); postal.InnerText = "68042"; XmlElement address = doc.CreateElement ("address"); address.AppendChild (street1); address.AppendChild (city); address.AppendChild (state); address.AppendChild (postal) XmlElement contact = doc.CreateElement ("contact"); contact.AppendChild (name); contact.AppendChild (phone1); contact.AppendChild (phone2); contact.AppendChild (address); XmlElement contacts = doc.CreateElement ("contacts"); contacts.AppendChild (contact); doc.AppendChild (contacts) / LINQ model XElement contacts = new XElement ("contacts", new XElement ("contact", new XElement ("name", "Patrick Hines"), new XElement ("phone", "20655-0144", new XAttribute ("type", "home"), new XElement ("phone", "425-555-0145", new XAttribute ("type", "work")), new XElement ("address", new XElement ("street1", "123Main St") New XElement ("city", "Mercer Island"), new XElement ("state", "WA"), new XElement ("postal", "68042"))

Here is just a very simple demonstration of some operations, as for those complex operations, as long as the DOM model can implement the LINQ model can be implemented. Methods such as AddAfterThis and AddBeforeThis can also be used to improve efficiency when inserting.

At this point, the study on "what is the difference between the DOM model and the LINQ model" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report