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!