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的基本代码的详细内容。
