- Home /
fileio System.Xml
hi unity(users),
After the release of Unity iPhone 1.6, I spend days looking for answers on the internet fora.
It's about C# FileIO. I know it is(was?) not possible in Basic... But... version 1.6 came along!!! And this little sentence in Unities announcement made my day:
System and System.Xml can now be used without stripping. Useful for Basic license owners.
I could not wait to install version 1.6. Suddenly, Unity became seriously useful for iPhone development!
But... whatever i tried nothing worked. The code below works fine in the editor, but trying to test it on the iPhone results - after packaging - in an error message, something like 'Sockets are only available in Advanced ...'
To make a long story short, unity iPhone basic can be very useful for my company if there is some basic fileIO. (paying 2 times 1000 euro's - just for fileIO in my case - is a bit too much these days)
Please, can anybody shed some light? Is there something wrong with this code? Or System.XML is still not useful in Basic?
thanks in advance - marco
BTW I know PlayerPrefs do work, but i need more space.
the test code:
using UnityEngine; using System.Collections;
using System.Xml;
public class Msg : MonoBehaviour {
static private Msg instance = null;
static public void set (string text) { Msg msg = GetInstance(); if (msg != null) msg.guiText.text = text; }
static public void Clear () { set(""); }
static public void add(string text {
Msg msg = GetInstance();
if (msg != null) msg.guiText.text += (text+"\n");
}
static public Msg GetInstance() {
if (instance == null) { instance = (Msg)FindObjectOfType(typeof(Msg));
if (instance == null) {
Debug.Log ("Could not locate a SimpleLogger object.");
}
} return instance;
}
void OnApplicationQuit() { instance = null; }
void Awake() {
Clear(); string s=Application.dataPath;
add(s.Substring((int)Mathf.Max(0,s.Length-60))); testWriteXml(); testReadXml();
}
private void testWriteXml(){
XmlTextWriter textWriter = new XmlTextWriter(Application.dataPath+"/myXmFile.xml", null); // Opens the document textWriter.WriteStartDocument(); // Write comments textWriter.WriteComment("First Comment XmlTextWriter Sample Example"); textWriter.WriteComment("myXmlFile.xml in root dir"); // Write first element textWriter.WriteStartElement("Student"); textWriter.WriteStartElement("r", "RECORD", "urn:record"); // Write next element textWriter.WriteStartElement("Name", ""); textWriter.WriteString("Student"); textWriter.WriteEndElement(); // Write one more element textWriter.WriteStartElement("Address", ""); textWriter.WriteString("Colony"); textWriter.WriteEndElement(); // WriteChars char[] ch = new char[3]; ch[0] = 'a'; ch[1] = 'r'; ch[2] = 'c'; textWriter.WriteStartElement("Char"); textWriter.WriteChars(ch, 0, ch.Length); textWriter.WriteEndElement(); // Ends the document. textWriter.WriteEndDocument(); // close writer textWriter.Close(); }
private void testReadXml()
{ // Create an isntance of XmlTextReader and call Read method to read the file XmlTextReader textReader = new XmlTextReader(Application.dataPath+"/myXmFile.xml"); textReader.Read(); // If the node has value while (textReader.Read()) { // Move to first element textReader.MoveToElement();
add("Name:" + textReader.Name);
}
}
}
Answer by Mantas-Puida · Mar 10, 2010 at 02:21 PM
It looks to me as a bug. We will investigate this issue.
Your answer
Follow this Question
Related Questions
Is there a method for getting application saved data off the iPhone? 2 Answers
iPhone System.IO.File.Exists() not working 1 Answer
How can I Javascript a phone call from within Unity? 1 Answer
iOS Target Resolution doesn't seem to affect resolution 0 Answers
how to store and retrieve data from sqlite in android and iPhone? 7 Answers