XML取自Unity3D手机游戏开发。
using UnityEngine; using System.Collections; using System.Xml; using System.IO; public class loadXml : MonoBehavIoUr { public TextAsset test; void Start () { string textData = test.text; XmlDocument xmlDoc = new XmlDocument (); xmlDoc.Load (new StringReader (textData)); XmlNodeList myNodeList = xmlDoc.SelectNodes ("ROOT"); foreach (XmlNode node in myNodeList) { Debug.Log (node.SelectNodes("table").Count); XmlNodeList childNodes = node.SelectNodes("table"); foreach(XmlNode node2 in childNodes){ Debug.Log (node2.Attributes.GetNamedItem("wave").InnerText); Debug.Log (node2.Attributes.GetNamedItem("enemyname").InnerText); Debug.Log (node2.Attributes.GetNamedItem("level").InnerText); Debug.Log (node2.Attributes.GetNamedItem("wait").InnerText); Debug.Log("------------------------"); } } } void Update () { } }
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ROOT> <table wave="100" enemyname="ground" level="100" wait="300"/> <table wave="1" enemyname="ground" level="1" wait="3"/> <table wave="2" enemyname="air" level="2" wait="4"/> <table wave="2" enemyname="air" level="2" wait="4"/> <table wave="3" enemyname="ground" level="2" wait="3"/> <table wave="3" enemyname="air" level="3" wait="3"/> <table wave="4" enemyname="ground" level="3" wait="5"/> <table wave="4" enemyname="ground" level="3" wait="4"/> <table wave="5" enemyname="air" level="4" wait="4"/> <table wave="5" enemyname="air" level="4" wait="4"/> <table wave="6" enemyname="ground" level="4" wait="4"/> <table wave="6" enemyname="ground" level="4" wait="5"/> <table wave="7" enemyname="air" level="5" wait="4"/> <table wave="7" enemyname="ground" level="5" wait="3"/> <table wave="8" enemyname="air" level="5" wait="4"/> <table wave="8" enemyname="ground" level="5" wait="4"/> <table wave="9" enemyname="air" level="6" wait="4"/> <table wave="9" enemyname="air" level="6" wait="5"/> <table wave="10" enemyname="ground" level="7" wait="4"/> <table wave="10" enemyname="air" level="7" wait="4"/> </ROOT>原文链接:https://www.f2er.com/xml/296176.html