Hi i currently have some problem about reading xml.
i have XML files at my streamingassets folder. when i load it from editor with
application.streamingassetspath + “/Dialog.xml” , and pass it to
XDocument.Load parameter it works perfect. but when i build it to android or windows phone it cant find the path…
so what i do wrong ? im so frustated, i can load xml file content with www.text, but XDocument.Load need a path not the content :s
btw this is my script, i get parameter xmlPath from application.streamingassetspath + “/Dialog.xml”
private string RequestDataFromXML(string xmlPath, string mainXmlTag, string id, string requestedAttribute)
{
string dataFromXML = "";
#if UNITY_ANDROID
//_dialogPath = "jar:file://" + Application.dataPath + "!/assets/Pattimura/Dialog.xml";
#endif
XDocument xml = XDocument.Load(xmlPath);
var queryIntro = from c in xml.Root.Descendants(mainXmlTag)
where c.Attribute("id").Value == id
select c.Attribute(requestedAttribute).Value;
foreach(string text in queryIntro) dataFromXML = text;
return dataFromXML;
}
for now i just hardcode streamingAssets path to “Data/StreamingAssets” for WP8 and it works perfectly.
I successfully read on PC, iOS and Android with this code:
string filepath = Path.Combine(Application.streamingAssetsPath, locale+"list.xml");
if (filepath.Contains ("://")) {
// in Android it need to be un-jared
StartCoroutine(extractText(filepath));
} else {
XmlDocument xmlDoc = new XmlDocument ();
if (File.Exists (filepath)) {
xmlDoc.Load (filepath);
XmlNodeList animalsList = xmlDoc.GetElementsByTagName ("item");
int i = 0;
foreach (XmlNode animal in animalsList) {
animalName [i++] = animal.InnerText.ToString ();
//Debug.Log (animal.InnerText);
}
} else
Debug.Log ("File: " + filepath + " does not exists");
}
IEnumerator extractText(string filepath) {
XmlDocument xmlDoc = new XmlDocument ();
WWW www = new WWW (filepath);
yield return www;
xmlDoc.LoadXml (www.text);
XmlNodeList animalsList = xmlDoc.GetElementsByTagName ("item");
int i = 0;
foreach (XmlNode animal in animalsList) {
animalName [i++] = animal.InnerText.ToString ();
//Debug.Log (animal.InnerText);
}
}
I am looking for solution for Windows Phone 8.