1# Resource Manager Development 2 3 4## How do I read an XML file in rawfile and convert the data in it to the string type? (API 9) 5 6**Solution** 7 8Call **getRawFileContent** of the **ResourceManager** module to obtain the data in the XML file, and then use **String.fromCharCode** to convert the data to the string type. 9 10**Example** 11 12``` 13resourceManager.getRawFileContent('test.xml', (error, value) => { 14 if (error != null) { 15 console.log("error is " + error); 16 } else { 17 let rawFile = value; 18 let xml = String.fromCharCode.apply(null, rawFile) 19 } 20}); 21``` 22 23**Reference Link** 24 25[ResourceManager \(Resource Management\)](../reference/apis-localization-kit/js-apis-resource-manager.md) 26 27 28## How do I obtain resources in the stage model? (API 9) 29 30**Solution** 31 32The stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This mode does not apply to the FA model. 33 34**Example** 35 36``` 37const context = getContext(this) as any 38context 39 .resourceManager 40 .getString($r('app.string.entry_desc').id) 41 .then(value => { 42 this.message = value.toString() 43}) 44``` 45 46 47## How do I obtain the path of the resource directory by using an API? (API 9)? 48 49**Symptom** 50 51How do I obtain the path of the **resource** directory so that I can manage the files in it by using the file management API? 52 53**Solution** 54 55Because the application is installed in HAP mode and the HAP package is not decompressed after the installation is complete, the resource path cannot be obtained when the program is running. 56 57To obtain the path of the **resource** directory, try either of the following ways: 58 591. Use **$r** or **$rawfile** for access. This method applies to static access, during which the **resource** directory remains unchanged when the application is running. 60 612. Use **ResourceManager** for access. This method applies to dynamic access, during which the **resource** directory dynamically changes when the application is running. 62 63**Reference Link** 64 65[Resource Categories and Access](../quick-start/resource-categories-and-access.md) and [ResourceManager \(Resource Management\)](../reference/apis-localization-kit/js-apis-resource-manager.md) 66 67 68## Why does getPluralString return an incorrect value? (API 9) 69 70**Symptom** 71 72The value obtained by the **getPluralString** is **other**, which is incorrect. 73 74**Solution** 75 76The **getPluralString** API is effective only when the system language is English. 77 78 79## How do I obtain the customized string fields in the resources directory? (API 9) 80 81**Solution** 82 83Use **getStringValue** of the **ResourceManager** module. 84 85**Reference Link** 86 87[ResourceManager \(Resource Management\)](../reference/apis-localization-kit/js-apis-resource-manager.md#getstringvalue9) 88 89 90## How do I reference resources such as images and text in AppScope? (API 9) 91 92**Solution** 93 94Resources are referenced in the **$r('app.type.name')** format. Where, **type** indicates the resource type, such as color, string, and media, and **name** indicates the resource name. 95 96 97## How do I convert resources to strings? (API 9) 98 99**Solution** 100 101If the resource type is set to **string**, the qualifier directory can be set as **this.context.resourceManager.getStringSync($r('app.string.test').id)** and can be converted synchronously. The **$r('app.string.test', 2)** mode is not supported. 102 103**Reference Link** 104 105[ResourceManager \(Resource Management\)](../reference/apis-localization-kit/js-apis-resource-manager.md#getstringsync9) 106 107 108## Can $ be used to reference constants in the form\_config.json file? (API 9) 109 110In the **form_config.json** file, **$** cannot be used to reference constants. 111 112 113## How does ArkTS parse XML files? (API 9) 114 115**Solution** 116 1171. Create the following XML file in the **rawfile** directory: 118 119 ``` 120 <?xml version="1.0" encoding="utf-8"?> 121 <user> 122 <name>Jacky</name> 123 <age>18</age> 124 </user> 125 ``` 126 1272. Use **resourceManager.getRawFileContent** to obtain the byte arrays of the XML file. 128 129 ``` 130 import resourceManager from '@ohos.resourceManager'; 131 resourceManager.getRawFileContent("test.xml", (error, value) => { 132 if (error != null) { 133 console.log("error is " + error); 134 return 135 } 136 let arrayBuffer = value.buffer; // unit8Array 137 var xmpParser = new xml.XmlPullParser(arrayBuffer); 138 var tagName = "" 139 //do something 140 } 141 ``` 142