Design Principles of LINQ to XML: in order to allow most developers to operate XML more easily and effectively, Microsoft has designed a brand new method in linqto XML. From the conceptual perspective or from the perspective of memory usage and performance, LINQ to
C # basic consolidation (3)-How To read XML from Linq To XML,
Record some methods for reading XML, so that you do not forget it when using it. You have to spend time searching it.I. Reading XML in traditional writing
Now I have an
Xdoc. Descendants () where s.name.localname = = "Name" s.value ==nametxt Select S.parent; foreach(XElement IteminchQuery//adding eligible nodes to the Eles collection{eles. ADD (item); } foreach(XElement IteminchEles//traverse the data to be traced, output{Console.WriteLine ("Id:{0},name:{1},sex:{2},age:{3}", item. Attribute ("ID"). Value,item. Element ("name"). Value,item. Element ("Sex"). Value,item. Element (" Age"). Value);
XML reading is needed in a recent project. The first thing I think of is to read data using LINQ (XML parsing is a little troublesome). after the project is completed, I will extract the content and take the following notes.
1. Demo. xml
Demo.
The core class XElement of LINQ to XML, a XElement represents a node, new XElement ("Order"), create a label named order, call Add Add child node, also XElement Object!
The following are common forms of several LINQ operations XML.
Write a file (Generate node Nature)
The code is as follows
Copy Code
XAttribute ("Age", "18"); ePersons. add (ptom); XElement pjack = new XElement ("Person"); pjack. add (new XAttribute ("Name", "jack"); pjack. add (new XAttribute ("Age", "20"); ePersons. add (pjack );
Final generation:
// Read the value of the node format in XML format
XDocument xd = XDocument. load ("XML file address"); foreach (XElement ite
The core class XElement of Linq To XML. An XElement represents a node, new XElement ("Order"), creates a label named "Order", and CALLS Add To Add subnodes, which is also an XElement object!
Below are some common forms of XML operations for LINQ.
/// Write the file (generate the node type)?
XElement ePersons =
How to read xml and linqxml by using linq
The xml file is as follows:
The related code is as follows:
String xmlPath = Application. startupPath + @ "\ config. xml "; XDocument xd = XDocument. load (xmlPath); string xmlx = ""; foreach (XElement item in xd. root. descen
The xml file is as follows: Read The implementation code is as follows:Public static string GetVideoFile (string url){String videoFilename = null;// Var ss = from e in XDocument. Load (url). Elements ("record_info"). Elements ("Vid_MM"). Elements ("RecFile ")Var query = from c in XDocument. Load (url). Elements ("record_info"). Elements ("VidInfo"). Elements ("Vid_MM"). Elements ("RecFile ")Where (string) c
LINQ to XML is a memory-based XML programming interface that enables LINQ. It can be used to process XML in. NET Framework programming languages.
It adds the XML documentIn MemoryThis is similar to the Document Object Model (DOM )
. NET provides LINQ to XML support for the System.Xml.Linq namespace. The Xdocument,xelement and Xtext,xattribute in this namespace provide a critical way to read and write XML documents.
1. Write XML using LINQ to XML:You can co
LINQ to XML provides a more convenient way to read and write xml. Some of the comments in the previous articles mentioned this. Why don't you use linq to xml? Now it's time to get out of the box.The System.
Overview:LINQ to XML (hereinafter referred to as LTX) is Microsoft's curd for XML based on LINQ technology. It is easier to use than the XML operation in System.Xml. This time use it in the company upgraded the boss's mail system, quite a bit of experience, now summed up.Main objects:1.xdocument:xml Document object loa
The System. Xml. Linq namespace in. Net provides the support for linq to xml. XDocument, XElement, and XText and XAttribute in this namespace provide key methods for reading and writing xml documents.
1. Use linq to
Using LINQ to XML makes it easy to access XML files. The posts written on the Internet are slightly messy. The one on the blog homepage todayArticleIt is not clear what I wrote. Below I will write down the method of accessing files using LINQ to XML in common, for the refere
Language-level integrated queries for XML (LINQ to XML) allow the use of standard query operators to query XML data just like a tree operator, which provides navigation like XPath to descendants, ancestors, and sibling XML elements. It simplifies the use of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.