Xml files are often used, but what is Xml? Xml files are used to store data. how can we traverse the data? Xml files are often used, but what is Xml? 
 
 
Here is an example: testResult. xml file
 
 
   
      
   
    
Serial Number
     
    
      
   
    
Inspection items
     
    
      
   
    
Unit
     
    
      
   
    
Standard requirements
     
    
      
   
    
Inspection result
     
    
      
   
    
Conclusion
     
  
  
The above is an Xml file. we know that the Xml file is used to store data. how can we traverse the data?
 
In fact, the simplest method is to use Linq:
 
Private void GetTestResultXml () {List
 
  
ITestResultXml = new List
  
   
(); // Define and load the node (root node) XElement rootNode = XElement from the xml file. load (@".. \.. \ Xml \ testResult. xml "); // query statement: obtain the name subnode under the root node (at this time, the subnode can be cross-level: Sun node, Sun node ......) IEnumerable
   
    
TargetNodes = from target in rootNode. Descendants ("column") select target; foreach (XElement node in targetNodes) {iTestResultXml. Add (node. Value );}}
   
  
  
In this way, we can obtain All the data in the tag is stored in the list iTestResultXml.
 
In the testResult. xml file, we can see that, The tag sets its own id. this id is not his data, but his attribute,
 
So how can we obtain his attributes instead of the content in his tags?
 
Private void GetTestResultXml () {List
 
  
IXmlID = new List
  
   
(); // Define and load the node (root node) XElement rootNode = XElement from the xml file. load (@".. \.. \ Xml \ testResult. xml "); // query statement: obtain the name subnode under the root node (at this time, the subnode can be cross-level: Sun node, Sun node ......) IEnumerable
   
    
TargetNodes = from target in rootNode. descendants ("column") select target; foreach (XElement node in targetNodes) {iXmlID. add (node. attribute ("id "). value); // method for obtaining the specified attribute }}
   
  
  
In this way, we can get The list of id attributes in the tag iXmlID.
 
The above is the details about how to traverse stored data in Xml-based Linq. For more information, see other related articles in the first PHP community!