Im pulling in xml data from the output of a php script. The way it works is that the php script outputs the xml data to the html page and the API im using pulls all text data that is displayed on that page into a string.
so the output of the html/php is supposed to be pretty standard xml format, Ive studied it and altered the php to make sure even the smallest details are outputted correctly.
Im then using the following code to deserialize the string into my class.
public static object XmlDeserializeFromFile(Type type, string strPath)
{
object data;
try
{
using (StreamReader reader = new StreamReader(strPath))
{
XmlSerializer serializer = new XmlSerializer(type);
data = serializer.Deserialize(reader);
reader.Close();
}
}
catch(Exception exception)
{
Debug.LogError (exception);
data = type.GetConstructor(Type.EmptyTypes).Invoke(null);
}
return data;
}
So the issue is that the string gets parsed from my code without hitting an exception, which makes me think that its working on some regard. However, the class still returns null values. Ive also verified that the string is being collected properly because it is displaying the full xml content in my debugger.
To test the class Im using the following code.
MyClass member = (MyClass)XmlDeserializeFromFile(typeof(MyClass), MyString);
if(member != null)
{
Debug.Log(member.a);
}
else
{
Debug.Log("Not Loaded");
}
And the result in my debugger keeps showing member.a = null.
My class properties are all public with {get; set;} and match the xml exactly, the class values populate correctly if i load from a file instead of a string.