- Home /
Reading XML file
Hi every one, i trying to read XML file from my server and instantiate gameobject throught xml file, when i read xml file, and then connect to server, and download what i need. Question is how can i type some if command, when i need to control "id" atribute. Here is C# script: using UnityEngine; using System.Collections; using System.Xml; using System.IO;
public class DownloadXML : MonoBehaviour {
private string urlXML = "http://www.raynoko.meximas.com/ENLI/XML/Models.xml";
private WWW www;
public string xmlData = "";
public string URL;
public GUIText guitext;
public IEnumerator Start(){
www = new WWW(urlXML);
yield return www;
xmlData = www.text;
}
public string getPathXml(string name) {
System.IO.StringReader stringReader = new System.IO.StringReader(xmlData);
stringReader.Read();
System.Xml.XmlReader readerObj = System.Xml.XmlReader.Create(stringReader);
while (readerObj.Read()) {
if(readerObj.Name == name){
//if(readerObj.IsStartElement("Models")){
URL = readerObj.GetAttribute ("web");
Debug.Log(URL);
guitext.text = readerObj.GetAttribute("description");
//}
}
}
return URL;
}
public string getPathXmlMat(string name) {
System.IO.StringReader stringReader = new System.IO.StringReader(xmlData);
stringReader.Read();
System.Xml.XmlReader readerMat = System.Xml.XmlReader.Create(stringReader);
while (readerMat.Read()) {
if(readerMat.Name == name){
URL = readerMat.GetAttribute ("mat");
}
}
return URL;
}
}
And i have XML file like this: So how can i type if commnad, or something like, that when i'll control "id" attribute? If anybody knows some webpage how read XMl file from unity script pls paste me. Thanks you Kind regards
I would suggest you to use Xml serialization ins$$anonymous$$d of just reading the file. This will be better since each XmlElement could be a separate object with it's own logic
Do you have any idea, how to write this code? Because work with X$$anonymous$$L through Unity is new for me... Some example simply code? Thanks