Detailed introduction to the basic code of XML

迷茫
Release: 2017-03-26 16:13:57
Original
3250 people have browsed it

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();
         }
     }
 }
Copy after login
<?xml version="1.0" encoding="utf-8" ?> 
<Computer>
  <Computers id="110">
  <Name>联想</Name>
   </Computers>
  <Computers id="120">
    <Name>苹果</Name>
  </Computers>
</Computer>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template