- Home /
Question by
claudekennilol · Jul 05, 2011 at 08:07 PM ·
loadxml
How do I load an xml file?
Hey, I've got this line here and I've got the archxmltext.xml in my resources folder.
XmlReader reader = new XmlTextReader("archxmltest");
But when I run it it says that it can't find "C:\Users\Name\Docs\Unity\My Project\archxmltest" instead of looking for it in the resources folder.. So basically I don't know how to load it properly, so if someone could point me in the right direction that'd be super helpful.
Comment
Best Answer
Answer by almo · Jul 05, 2011 at 08:35 PM
http://x9productions.com/blog/?p=26
var asset:TextAsset = Resources.Load("testxml");
if(asset != null)
{
var reader:XmlTextReader = new XmlTextReader(new StringReader(asset.text));
while(reader.Read())
{
if(reader.Name == "item1")
{
Debug.Log(reader.Name + " label = " + reader.GetAttribute("label"));
}
}
}
Excellent! Please also click the checkmark to "Accept" the answer. This marks it so other people know it's finished.
Oh! thanks, I didn't know I had to do more than click the thumbs up icon. Will do that now.
No problem. It takes a little time to get used to this system. :)
Your answer
