The emergence of linq brings us a simple knot, fast, and readable. It consists of linq to SQL, linq to object, and linq to XML, my blog has previously explained how to operate the SQL statements. Today, I will talk about a linq to xml architecture that reads and writes the XML files, it will let you operate your xml file like using linq to SQL. Let's take a look at the following XML file.
True false true d: \ path \ document \ thrift file \ testJava. thrift 1297 8C: 89: A5: E1: 89: 3D 1 15:32:46 0 true false true d: \ path \ material \ thrift file \ thrift-0.8.0.exe 4013056 8C: 89: A5: E1: 89: 3D 1 15:32:46 0 true false true d: \ path \ Documents \ thrift file \ thrift_white leather books 441217 8C: 89: A5: E1: 89: 3D 1 15:32:46 0 true false true d: \ path \ Documents \ thrift file \ thriftcommand .txt 131 8C: 89: A5: E1: 89: 3D 1 15:32:46 0
This file is automatically generated by thrift. Now we use linq to xml to read the content in this file. Of course, you can also use XML deserialization, deserialize it into an object and read it again.
System.Console.WriteLine( data = e XElement.Load( = Convert.ToInt32(e.Element(= Convert.ToBoolean(e.Element(= e.Element(= Convert.ToInt64(e.Element(= e.Element(= e.Element(=> System.Console.WriteLine(i.ToString()));
The output result is as follows:
In the above example, our XML file uses the element method or the attribute form, and the code can be slightly modified.