Unity uses Mono. Xml instead of System. Xml for testing. mono. xmlsystem. xml
Test Environment
Operating System: Windows8.1
Development Tool: Unity5.5.2
1. Create a new test project and observe the correctness of the parsing files referenced by System. Xml and Mono. Xml, and the size of the packaged APK.
2. Mono. Xml use case
using UnityEngine;using Mono.Xml;using System.Security;public class MonoXmlTest : MonoBehaviour { void Start () { SecurityParser parser = new SecurityParser(); string xmlPath = "test"; parser.LoadXml(Resources.Load(xmlPath).ToString()); SecurityElement element = parser.ToXml(); foreach (SecurityElement node in element.Children) { if (node.Tag == "table") { string wave = node.Attribute("wave"); string level = node.Attribute("level"); string name = node.Attribute("name"); Debug.Log("wave:" + wave + " level:" + level + " name:" + name); } } } }
3. System. xml use case
using UnityEngine;using System.Xml;public class SystemXmlTest : MonoBehaviour { // Use this for initialization void Start () { XmlDocument xml = new XmlDocument(); XmlReaderSettings set = new XmlReaderSettings(); xml.LoadXml(Resources.Load("test").ToString()); XmlNodeList nodes = xml.SelectSingleNode("ROOT").ChildNodes; foreach (XmlElement node in nodes) { string wave = node.GetAttribute("wave"); string level = node.GetAttribute("level"); string name = node.GetAttribute("name"); Debug.Log("wave:" + wave + " level:" + level + " name:" + name); } } }
4. Conclusion: Mono. Xml is used to replace System. Xml. After the APK installation package is compiled, the size is reduced by about KB. We recommend that you use Mono. Xml.