x


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:UsersNameDocsUnityMy Projectarchxmltest" 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.

more ▼

asked Jul 05 '11 at 08:07 PM

claudekennilol gravatar image

claudekennilol
146 7 9 12

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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"));
        }
    }
}
more ▼

answered Jul 05 '11 at 08:35 PM

almo gravatar image

almo
1.7k 2 6 18

Thanks, that was able to do it for me.

Jul 05 '11 at 11:40 PM claudekennilol

Excellent! Please also click the checkmark to "Accept" the answer. This marks it so other people know it's finished.

Jul 05 '11 at 11:47 PM almo

Oh! thanks, I didn't know I had to do more than click the thumbs up icon. Will do that now.

Jul 07 '11 at 04:51 PM claudekennilol

No problem. It takes a little time to get used to this system. :)

Jul 07 '11 at 04:54 PM almo
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x436
x255

asked: Jul 05 '11 at 08:07 PM

Seen: 1886 times

Last Updated: Jul 07 '11 at 04:54 PM