In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "LINQ to XML operation example analysis", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "LINQ to XML operation example analysis" bar!
LINQ to XML operation
XElement xelem = XElement.Load (@ "example.xml"); / / query node name Item and return a collection of their PartNumber attribute values IEnumerable partNos = from item in xelem.Descendants ("Item") Select (string) item.Attribute ("PartNumber"); foreach (string strin partNos) Console.WriteLine (str)
In. Net 3.5, the framework extends the LINQ to XML operation, which is called LINQ to XML. Under the namespace System.Xml.LINQ. From the above code, we can see that a new XElement object has been added. We load the XML document through the XElement.Load method instead of the traditional DOM schema XmlDocument.Load.
Compared to the W3C DOM document structure, LINQ to XML provides us with a more convenient way to create an XML document.
XElement contacts = new XElement ("Contacts", new XElement ("Name", "Ice Lee"), new XElement ("Phone", "010-876546", new XAttribute ("Type", "Home")), new XElement ("Phone", "425-23456", new XAttribute ("Type", "Work"), new XElement ("Address", new XElement ("Street", "ZhiXinCun"), new XElement ("City", "Beijin") / / output result: Ice Lee 010-876546 425-23456 ZhiXinCun Beijing
LINQ to XML provides rich and concise classes to implement operations on XML. Compared with the XML class library of a wide variety of DOM models, LINQ classes make our learning curve smooth and achieve the same effect. LINQ to XML solves several inconvenient problems in the DOM model, such as changing node names, and abandons things that look powerful but rarely used, such as entities and entity references. This makes LINQ to XML operation faster and more convenient. The following examples will show you how LINQ to XML can modify, add and delete node names.
First, let's take a look at how adding a node to XML is implemented:
XElement xelem = XElement.Load (@ "example.xml"); XElement newnewXelem = new XElement ("NewNode", "This is new node"); xelem.Add (newXelem); Thank you for reading, the above is the content of "LINQ to XML Operation example Analysis". After the study of this article, I believe you have a deeper understanding of the problem of LINQ to XML operation example analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.