XML文件操作--读取
发布时间:2020-12-16 06:14:34 所属栏目:百科 来源:网络整理
导读: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
<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)); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |