溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

XML的基本代碼詳解

發(fā)布時間:2020-05-08 15:09:44 來源:億速云 閱讀:360 作者:Leah 欄目:編程語言

這篇文章主要介紹了XML的基本代碼,具有一定借鑒價值,需要的朋友可以參考下。如下資料是關(guān)于XML的基本代碼的內(nèi)容,希望對大家有所幫助。

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>聯(lián)想</Name>
   </Computers>
  <Computers id="120">
    <Name>蘋果</Name>
  </Computers>
</Computer>

關(guān)于XML的基本代碼詳解就分享到這里了,希望以上內(nèi)容可以對大家有一定的參考價值,可以學(xué)以致用。如果喜歡本篇文章,不妨把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

xml
AI