Read xml from Resouces folder, and convert to array/dictionary

Create a XML file with name “DB.xml”, and put into “Resources” folder.


Switch to Unity

using System.Xml.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
Void Start(){
  TextAsset myXML = (TextAsset) Resources.Load("DB");
  var dbArr = XDocument.Load(new System.IO.StringReader(myXML.text)).Root.Elements().
Select(y => y.Elements().ToDictionary(x => x.Name, x => x.Value)).ToArray();
  Debug.Log("try to get first item's name:"+dbArr[0]["name"]);

回复 (0)

› 尚无评论。

引用通告 (0)

› 尚无引用通告。