Home  >  Article  >  Backend Development  >  Detailed introduction to the basic code of XML

Detailed introduction to the basic code of XML

迷茫
迷茫Original
2017-03-26 16:13:573170browse

Detailed explanation of the basic code of XML

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Xml;
 
 namespace Day08_XML
 {
     class Program
     {
         static void Main(string[] args)
         {
             XmlDocument doc = new XmlDocument();
             doc.Load("Computer.xml");
            XmlNode root=doc.DocumentElement;
             foreach(XmlNode item in root.ChildNodes){
                 string id = item.Attributes["id"].Value;
                
            
                 Console.WriteLine(id);
                 Console.WriteLine("名称为"+item["Name"].InnerText);
             
             
             }
 
            //foreach(XmlNode item in root.ChildNodes){
 
                         //item是XML中的Computer对象
            //     foreach(XmlNode child in item.ChildNodes){
 
            //         switch(child.Name){
                     
            //             case "Name":
            //                 Console.WriteLine("我的电脑是:"+child.InnerText);
            //                 break;
                     
                     
                     
            //         }
                  
             
            // }
          
 
            // }
             Console.ReadLine();
         }
     }
 }
<?xml version="1.0" encoding="utf-8" ?> 
<Computer>
  <Computers id="110">
  <Name>联想</Name>
   </Computers>
  <Computers id="120">
    <Name>苹果</Name>
  </Computers>
</Computer>

The above is the detailed content of Detailed introduction to the basic code of XML. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn