Search Unity

Loading XML on android device using XmlSerializer

Discussion in 'Editor & General Support' started by gaz99, May 12, 2014.

  1. gaz99

    gaz99

    Joined:
    May 1, 2014
    Posts:
    9
    Hi,
    When loading XML files in the editor using the following code, the XML loads fine in the editor, however when testing on an android device it doesn't work. I've tried searching for a solution but none of the ones posted don't seem to work.

    Code (csharp):
    1. FileStream fs = new FileStream("teams.xml", FileMode.Open);
    2.  
    3.         XmlSerializer serial = new XmlSerializer(typeof(TeamsCollection));
    4.         teamCol = (TeamsCollection)serial.Deserialize(fs);
    Can anybody help with this.

    Thanks
     
  2. gaz99

    gaz99

    Joined:
    May 1, 2014
    Posts:
    9
    Solution was to use this method
    Code (csharp):
    1.  
    2. TextAsset textAsset = (TextAsset)Resources.Load("teams", typeof(TextAsset));
    3. StringReader stringReader = new StringReader (textAsset.text);
    4. XmlTextReader reader = new XmlTextReader (stringReader);
    5.  
    6. XmlSerializer serial = new XmlSerializer(typeof(TeamsCollection));
    7. teamCol = (TeamsCollection)serial.Deserialize(reader);