How about using LINQ to XML
?
XDocument xDoc = XDocument.Parse("textXML.text");
var myList = xDoc.Descendants("AlertInfo").Select(x => new AlertInfo()
{
strId = (string) x.Attribute("id"),
strName = (string) x.Attribute("Name"),
vectSpawnPos = new Vector3
{
x = (float) x.Attribute("pos_X"),
y = (float) x.Attribute("pos_Y"),
z = (float) x.Attribute("pos_Z")
}
}).ToList();
To use this code you need to make a little change.Make your vectSpawnPos
auto-implemented property like:
public Vector3 vectSpawnPos { get; set; }
And your Vector3
class should look like:
public class Vector3
{
public float x { get; set; }
public float y { get; set; }
public float z { get; set; }
}