xml简单的方法数据解析
Script1
using System.Collections;
public class XMLNode: Hashtable
{
public XMLNodeList GetNodeList(string path)
{
return GetObject(path) as XMLNodeList;
}
public XMLNode GetNode(string path)
{
return GetObject(path) as XMLNode;
}
public string GetValue(string path)
{
return GetObject(path) as string;
}
private object GetObject(string path)
{
string[] bits = path.Split('>');
XMLNode currentNode = this;
XMLNodeList currentNodeList = null;
bool listMode = false;
object ob;
for (int i = 0; i < bits.Length; i++)
{
if (listMode)
{
currentNode = (XMLNode)currentNodeList[int.Parse(bits[i])];
ob = currentNode;
listMode = false;
}
else
{
ob = currentNode[bits[i]];
if (ob is ArrayList)
{
currentNodeList = (XMLNodeList)(ob as ArrayList);
listMode = true;
}
else
{
// reached a leaf node/attribute
if (i != (bits.Length - 1))
{
// unexpected leaf node
string actualPath = "";
for (int j = 0; j <= i; j++)
{
actualPath = actualPath + ">" + bits[j];
}
//Debug.Log("xml path search truncated. Wanted: " + path + " got: " + actualPath);
}
return ob;
}
}
}
if (listMode)
return currentNodeList;
else
return currentNode;
}
}
Script2
using System.Collections;
public class XMLNodeList: ArrayList
{
public XMLNode Pop()
{
XMLNode item = null;
item = (XMLNode)this[this.Count - 1];
this.Remove(item);
return item;
}
public int Push(XMLNode item)
{
Add(item);
return this.Count;
}
}
Script3
/*
* UnityScript Lightweight XML Parser
* by Fraser McCormick (unityscripts@roguishness.com)
* http://twitter.com/flimgoblin
* http://www.roguishness.com/unity/
*
* You may use this script under the terms of either the MIT License
* or the Gnu Lesser General Public License (LGPL) Version 3.
* See:
* http://www.roguishness.com/unity/lgpl-3.0-standalone.html
* http://www.roguishness.com/unity/gpl-3.0-standalone.html
* or
* http://www.roguishness.com/unity/MIT-license.txt
*/
/* Usage:
* parser=new XMLParser();
* var node=parser.Parse("<example><value type=\"String\">Foobar</value><value type=\"Int\">3</value></example>");
*
* Nodes are Boo.Lang.Hash values with te