I am trying to deserialize an xml file. My code is based on answers I’ve read, I googled for a solution end everyone keeps stating to check the xml to see if it has a root but I have no problem with this. This is my xml:
<?xml version="1.0" encoding="utf-8"?>
<tips>
<tip>
All nutrition facts labels have the same format, with serving size and calories listed on top. Below this:
● List of essential nutrients including: total fat, cholesterol, sodium, potassium, total carbohydrates and finally protein.
● Below that: the essential nutrients, some vitamins and minerals.
● Finally, the ingredient list.
The serving size for the product helps you determine if you actually consume the amount listed as the serving size. For example, the serving size for ready-to-eat cereal is one cup. If you eat two cups of cereal, you would need to multiply the numbers on the nutrition facts label by two.
</tip>
<tip>
The total fat is important for determining what types of fat the product contains. Fats such as mono and polyunsaturated fats are more heart healthy fats while saturated and trans-fats are detrimental to overall health. The American Heart Association (AHA) recommends avoiding products that contain
any industrially manufactured trans-fat, meaning “partially hydrogenated oils”.
</tip>
</tips>
And here is my code to find and deserialize the file:
string absolute_path = Application.streamingAssetsPath + file_path + ".xml";
Debug.Log("This is the file path" + absolute_path);
WWW www = new WWW(absolute_path);
while (!www.isDone)
{
}
XmlSerializer serializer = new XmlSerializer(typeof(Tips));
MemoryStream stream = new MemoryStream(www.bytes);
if(stream != null)
{
Debug.Log("Stream is not null");
tips = serializer.Deserialize(stream) as Tips;
}
stream.Close();
This is the Tips class:
[XmlRoot("tips")]
public class Tips
{
[XmlElement("tip")]
public List<string> tip { get; set; }
}
Any help will be greatly appreciated