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) { XmlDocume
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>以上就是详细介绍XML的基本代码的详细内容,更多请关注自由互联其它相关文章!
