The contents of the 1.xml file are as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<info>
<book id = "B1" lang = "en" >
<name>c++</name>
<price>555</price>
</book>
<book id = "B2" lang = "en" >
<name>c#</name>
<price>666</price>
</book>
</info>
This file can be placed under the resources or streamingassets, so there are two ways to read the path, read as follows
Using Unityengine;
Using System.IO;
Using System.Xml;
Using System.Collections;
public class Readxml:monobehaviour {
<summary>
Resources to read XML under the method
</summary>
void Start ()
//{
The reading method under the resources
Textasset Textasset = resources.load ("XMLFile1", typeof (Textasset)) as Textasset;
ReadXML (new MemoryStream (textasset.bytes));
//}
<summary>
Streamingassets The following method of reading XML
</summary>
<returns></returns>
IEnumerator Start ()
{
www www = new www ("file://" + Application.streamingassetspath + "/xmlfile1.xml");
yield return www;
ReadXML (new MemoryStream (www.bytes));
Www.Dispose ();
}
Update is called once per frame
void Update ()
{
}
void ReadXML (Stream stream) {
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (stream);
XmlNode info = xmldoc.selectsinglenode ("info");
foreach (XmlNode node in info. ChildNodes)
{
String id = node. attributes["id"]. InnerText;
String lang = node. attributes["Lang"]. InnerText;
String name = node. selectSingleNode ("name"). InnerText;
Debug.Log (node. Name + "/" + "id =" + id + "lang =" + lang + "name =" + name);
}
}
}
Two ways to read XML