2 回答

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
我真的已經(jīng)傻了!如果其他人有這個(gè)問題,請(qǐng)查看您的文件(在我的情況下xml)并將構(gòu)建操作從Embedded更改為Content。如果你這樣做,你可以這樣做:
Doc.Load(@"\Data\ClassData.xml");

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊
對(duì)于項(xiàng)目中的文件,試試這個(gè):
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.lbl_Werkt.Text = "het werkt wtf";
try{
XmlDocument Doc = new XmlDocument();
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Data\ClassData.xml");
if(!file.Exists(path))
throw new IOExpection("File not found");
Doc.Load(path);
foreach (XmlNode node in Doc.SelectNodes("//Warrior"))
{
string Name = node["Name"].InnerText;
lbl_Name.Text = Name;
}
}
catch(IOException ioEx)
{
Console.WriteLine("The File could not be read:");
Console.WriteLine(ioEx.Message);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
- 2 回答
- 0 關(guān)注
- 320 瀏覽
添加回答
舉報(bào)