I can load a comma deliminated version of my xml data into my class fine, but in order to make it cleaner I wanted to output the data from my server in xml format and then load it in unity.
In none xml format, I use WWW.text and then parse it. so Im assuming that to get xml from the web I would use the same thing.
I can also load an xml file fine using the following code:
public static object Load(Type type, string path)
{
object data;
try
{
StreamReader reader = new StreamReader(path);
XmlSerializer xml = new XmlSerializer(type);
data = xml.Deserialize(reader);
reader.Close ();
}
catch
{
data = null;
}
return data;
}
However getting an xml schema from www.text and then deserializing it has not worked for me. Ive tried multiple derivative of the above code. Could some one aid me in collecting xml from www.text?
the output from my server is standard xml format.
EDIT:
Here is a slightly modified version that has given me the most luck. It seems it is loading the xml file because an exception isnt thrown in my catch block, although the class values its supposed to populate are still showing up null. Again, when i use the version that loads from files it works perfectly.
public static object LoadXML(Type type, string url)
{
object data;
try
{
using (StringReader reader = new StringReader(url))
{
XmlSerializer xml = new XmlSerializer(type);
data = xml.Deserialize(reader);
reader.Close();
}
}
catch(Exception exception)
{
Debug.LogError (exception);
data = type.GetConstructor(Type.EmptyTypes).Invoke(null);
}
Debug.Log (data.ToString());
return data;
}