Reading XML Resource File in Javascript WinRT Application

I am trying to configure a configuration file for some application elements (such as API keys) for my WinRT experiment.

So far, I have added the config.xml file to the root of my project, marking it as a resource in the properties ... and then stuck.

Every example I can find seems to be dealing with JSON resource files (which are somehow tied to localization by convention and don't seem to be suitable for shared configuration files?) Loading files from disk (which does not work with resources compiled into a .pri file) or uses C #.

So how can I make this work in my Javascript / HTML5 application?

My last attempt:

var uri = new Windows.Foundation.Uri('ms-resource:///config'); var xml = Windows.ApplicationModel.Resources.ResourceLoader .getStringForReference(uri); 

but this does not work and throws the following exception:

 0x80073b1f - JavaScript runtime error: ResourceMap Not Found. 

What am I missing?


I feel myself approaching:
 var r = Windows.ApplicationModel.Resources.Core.ResourceManager .current.mainResourceMap.lookup('Files/config.xml'); var candidates = r.resolveAll(); candidates[0].getValueAsFileAsync().done(readXml); 

This finds the file resource, but the entire candidate contains the original absolute path to the file, so getValueAsFileAsync() throws an exception: "The system cannot find the specified file." (and the readXml not called).

Therefore, I still cannot understand the contents of this XML file.

+6
source share
1 answer

Try it...

 var uri = new Windows.Foundation.Uri('ms-appx:///myFolder/myConfig.xml'); var file = Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri); 

Now you can use the file to parse and process the data as needed.

+3
source

Source: https://habr.com/ru/post/926365/


All Articles