<pre name="code" class="html"><span style="font-family: Arial,Helvetica,sans-serif;"><?xml version="1.0" encoding="utf-8" ?></span><root> <testmark mark="3" /> <test0 a="a0" b="b0" c="c0"/> <test1 a="a1" b="b1" c="c1"/> <test2 a="a2" b="b2" c="c2"/> <test3 a="a3" b="b3" c="c3"/></root>
上面的XML保存在Unity项目如下目录中:
Application.dataPath + "/res/XMLFile1.xml"
头文件:using System.Xml;
private void loadXML1() { //Debug.LogError(Application.dataPath + "/res/XMLFile1.xml"); XmlDocument doc = new XmlDocument(); doc.Load(Application.dataPath + "/res/XMLFile1.xml"); XmlNode root = doc.DocumentElement;//获取XML的根 XmlNode nodemark = root.SelectSingleNode("testmark"); string strmark = nodemark.Attributes["mark"].Value; XmlNode node = root.SelectSingleNode(string.Format("test{0}",strmark)); Debug.LogError(string.Format("node.Attributes[\"a\"].Value = {0},node.Attributes[\"b\"].Value = {1},node.Attributes[\"c\"].Value = {2}",node.Attributes["a"].Value,node.Attributes["b"].Value,node.Attributes["c"].Value)); }原文链接:https://www.f2er.com/xml/296477.html