XML文件操作--读取

前端之家收集整理的这篇文章主要介绍了XML文件操作--读取前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<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

猜你在找的XML相关文章