您好,登錄后才能下訂單哦!
這篇文章主要介紹了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é)以致用。如果喜歡本篇文章,不妨把它分享出去讓更多的人看到。
免責(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)容。