On Nov 27, 2012, at 3:09 PM, JM_SH <juanmanuelsanch...@gmail.com> wrote:
> In my project I have to use an xml file. For that reason I created a
> subfolder into the resources one, and it`s name is xml.

You then (presumably) added a Data.xml file to the Resources\Xml folder; what 
Build action did you set on it?

Default should be AndroidResource, but it wouldn't help to verify...

> After that, in my projecto, I use the xmldocument method in this way:
> xmlDocument xDoc = new xmlDocument();
> xDoc.Load("Data.xml");

This won't work/ xDoc.Load() wants a filename, and there is no such file. Files 
with a Build action of AndroidResource are embedded into the .apk and are not 
extracted at install time; in order to access such files, you need to use the 
Resources [0, 1] API:

        var doc = new XmlDocument ();
        doc.Load (context.Resources.GetXml (Resource.Xml.Data));

Alternatively, instead of using the Android Resources API, you may want to 
embed the file into your assembly. This will allow your code to be portable 
across Windows and MonoTouch as well. You'd set the Build action for Data.xml 
to EmbeddedResource, and use Assembly.GetManifestResourceStream()[2]:

        var doc = new XmlDocument ();
        doc.Load (Assembly.GetExecutingAssembly ().GetManifestResourceStream 
(@RESOURCE_NAME@));

Note: You'll need to double-check/change the Resource ID when using the 
EmbeddedResource build action, as @RESOURCE_NAME@ frequently will NOT be the 
filename; see the file's Properties panel.

 - Jon

[0]: http://androidapi.xamarin.com/?link=T:Android.Content.Res.Resources
[1]: http://androidapi.xamarin.com/?link=P:Android.Content.Context.Resources
[2]: 
http://androidapi.xamarin.com/?link=M:System.Reflection.Assembly.GetManifestResourceStream(string)

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to