Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Loading XML

Discussion in 'Scripting' started by KenSyuu, Apr 17, 2014.

  1. KenSyuu

    KenSyuu

    Joined:
    Nov 16, 2013
    Posts:
    14
    Hi all, first heres part of the code I've written

    Code (csharp):
    1.  
    2.     private string[] xmlPaths = new string[] {
    3.         "/GameData/MapXML/HK_Island_Estates.xml",
    4.         "/GameData/MapXML/Kowloon_Estates.xml",
    5.         "/GameData/MapXML/Lantau_Estates.xml",
    6.         "/GameData/MapXML/NewTerritories_Estates.xml"
    7.     };
    8.  
    9.     void Start () {
    10.         LoadEstatesXml (Application.dataPath + xmlPaths [0]);
    11.     }
    12.  
    13.     void LoadEstatesXml (string xmlPath)
    14.     {
    15.         xmlDoc = new XmlDocument ();
    16.         xmlDoc.LoadXml (File.ReadAllText (xmlPath));
    17.         xmlNode = xmlDoc.SelectSingleNode ("district");
    18.     }
    19.  
    20.  
    When I run on my PC, it works fine as I can get the path C:/Users/Public/Documents/...../HK_Island_Estates.xml
    However when I run on Android, I got error:
    Could not find a part of the path "/data/app/com.myTest.Game.apk/GameData/MapXML/HK_Island_Estates.xml

    Could anyone advise why is this happening?
    Thanks!!
     
  2. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    Do you create the xml in script or by yourself? If not by script, the android version probably doesn't have the xml files.
     
  3. KenSyuu

    KenSyuu

    Joined:
    Nov 16, 2013
    Posts:
    14
    The XML are prepared outside the script and I've put them under the GameData folder as in the Unity3D editor (in the Project panel)
    Will it not work?