I am trying to read and write XML to iOS. Everything works fine in the iOS simulation, but when I try to build an app on my device the problems seems to be starting.
I have added the xml file to Copy Bundle Resources with "Copy items into destination group´s folder (if needed) check and “Create groups for any added folders” checked.
This is my code for loading the XML file :
string path = path = Application.persistentDataPath + "/gamexmldata.txt";
public void LoadFromXml()
{
Debug.Log ("Du nådde LoadXML metoden");
XmlDocument xmlDoc = new XmlDocument();
if(File.Exists(path))
{
Debug.Log("Filen finnes");
Debug.Log(path.ToString());
xmlDoc.Load(path);
XmlNodeList transformList = xmlDoc.GetElementsByTagName("rotation");
foreach (XmlNode transformInfo in transformList)
{
XmlNodeList transformcontent = transformInfo.ChildNodes;
foreach (XmlNode transformItens in transformcontent)
{
if(transformItens.Name == "x")
{
Debug.Log(transformItens.InnerText);
resultatFraXML += transformItens.InnerText;
}
if(transformItens.Name == "y")
{
Debug.Log(transformItens.InnerText);
resultatFraXML += transformItens.InnerText;
}
if(transformItens.Name == "z")
{
Debug.Log(transformItens.InnerText);
resultatFraXML += transformItens.InnerText;
}
if(transformItens.Name == "name")
{
resultatFraXML += transformItens.InnerText;
guitext.text = resultatFraXML;
GameControl.control.outputXml = resultatFraXML;
Debug.Log(resultatFraXML);
}
}
}
}
}
The error I get is :
XmlException: Document element did not appear. file:///var/mobile/Applications/47C26549-9CB0-46C2-9906-66399A5E515C/Documents/gamexmldata.txt Line 1, position 1.
at Mono.Xml2.XmlTextReader.Read () [0x00000] in <filename unknown>:0
at System.Xml.XmlTextReader.Read () [0x00000] in <filename unknown>:0
at Mono.Xml.EntityResolvingXmlReader.Read () [0x00000] in <filename unknown>:0
at Mono.Xml.DTDValidatingReader.ReadContent () [0x00000] in <filename unknown>:0
at Mono.Xml.DTDValidatingReader.Read () [0x00000] in <filename unknown>:0
at Mono.Xml.Schema.XsdValidatingReader.Read () [0x00000] in <filename unknown>:0
at System.Xml.XmlValidatingReader.Read () [0x00000] in <filename unknown>:0
at System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
at System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
at System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader) [0x00000] in <filename unknown>:0
at System.Xml.XmlDocument.Load (System.String filename) [0x00000] in <filename unknown>:0
at ReadXmlData.LoadFromXml () [0x00000] in <filename unknown>:0
at ReadXmlData.Start () [0x00000] in <filename unknown>:0
(Filename: Line: -1)
I was thinking it might be UTF-8 and BOM problems, but I have done all converting and checking etc. Can´t find any BOM at all.
By accident the same error came when I played around with the Unity editor and then it appeared that the file was empty. Earlier on my debugging I did a File.Create in the code. Could it be that I have a empty file in the app that has NO data in it all? Or is the file placed in a wrong directory?
Any good ideas to why I get this kind of error?