In the development process, we often need to use many resource files, such as the city name and Pinyin ing list.
Why should these files be used as local resource files? This is generally because:
1. We do not like to hard code these resources into code, such as a city list "Beijing-Beijing, Shanghai-Shanghai ,......", If it is hard-coded into the code, it is obviously not as flexible as getting XML (or JSON, or even TXT files.
2. Although such resources can be obtained from the network, it is better to perform frequent operations locally (and then load them to the memory ), in addition, such resources are not very large.
WP7 is easy to read local resource files. For example, we have a city. xml file to read:
First, copy the file to our project, and then set its properties {copy to the output directory: Always copy, generate operation: Resource} (of course, it can also be set to copy data if it is newer. I personally feel that there is no difference in the use effect)
Then, the Code calls:
Streamresourceinfo reader = application. getresourcestream (New uri ("/{your project name}; component/{file path}", urikind. Relative ));
Xelement xml = xelement. Load (reader. Stream );
It may also be because I am not using JSON much. I personally feel that XML in WP7 is easier to use than JSON. This is not the focus of this Article. If you do not know about XML parsing, you can refer to relevant materials.