From 02115071fd54f45a5c65a2ca5da015d6dbb61ee2 Mon Sep 17 00:00:00 2001 From: wusongqing Date: Tue, 28 Jun 2022 20:06:23 +0800 Subject: [PATCH] update docs against 5767 Signed-off-by: wusongqing --- .../reference/apis/js-apis-url.md | 218 ++++++++++-------- .../reference/apis/js-apis-util.md | 41 ++-- .../reference/apis/js-apis-xml.md | 75 +++++- 3 files changed, 208 insertions(+), 126 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-url.md b/en/application-dev/reference/apis/js-apis-url.md index b3d39d36eb..d97e984d43 100755 --- a/en/application-dev/reference/apis/js-apis-url.md +++ b/en/application-dev/reference/apis/js-apis-url.md @@ -1,6 +1,7 @@ # URL String Parsing -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> **NOTE** +> > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -10,10 +11,6 @@ import Url from '@ohos.url' ``` -## System Capabilities - -SystemCapability.Utils.Lang - ## URLSearchParams @@ -23,20 +20,22 @@ constructor(init?: string[][] | Record<string, string> | string | URLSearc Creates a **URLSearchParams** instance. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| init | string[][] \| Record<string, string> \| string \| URLSearchParams | No| Input parameter objects, which include the following:
- **string[][]**: two-dimensional string array
- **Record<string, string>**: list of objects
- **string**: string
- **URLSearchParams**: object| +| init | string[][] \| Record<string, string> \| string \| URLSearchParams | No| Input parameter objects, which include the following:
- **string[][]**: two-dimensional string array
- **Record<string, string>**: list of objects
- **string**: string
- **URLSearchParams**: object | **Example** ```js -var objectParams = new URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); -var objectParams1 = new URLSearchParams({"fod" : 1 , "bard" : 2}); -var objectParams2 = new URLSearchParams('?fod=1&bard=2'); -var urlObject = new URL('https://developer.mozilla.org/?fod=1&bard=2'); -var params = new URLSearchParams(urlObject.search); +var objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); +var objectParams1 = new Url.URLSearchParams({"fod" : 1 , "bard" : 2}); +var objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); +var urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); +var params = new Url.URLSearchParams(urlObject.search); ``` @@ -46,18 +45,20 @@ append(name: string, value: string): void Appends a key-value pair into the query string. +**System capability**: SystemCapability.Utils.Lang + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| name | string | Yes| Key of the key-value pair to append.| -| value | string | Yes| Value of the key-value pair to append.| +| name | string | Yes | Key of the key-value pair to append. | +| value | string | Yes | Value of the key-value pair to append. | **Example** ```js -let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); -let paramsObject = new URLSearchParams(urlObject.search.slice(1)); +let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); paramsObject.append('fod', 3); ``` @@ -68,17 +69,19 @@ delete(name: string): void Deletes key-value pairs of the specified key. +**System capability**: SystemCapability.Utils.Lang + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| name | string | Yes| Key of the key-value pairs to delete.| +| name | string | Yes | Key of the key-value pairs to delete. | **Example** ```js -let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); -let paramsobject = new URLSearchParams(urlObject.search.slice(1)); +let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsobject = new Url.URLSearchParams(urlObject.search.slice(1)); paramsobject.delete('fod'); ``` @@ -89,23 +92,25 @@ getAll(name: string): string[] Obtains all the key-value pairs based on the specified key. +**System capability**: SystemCapability.Utils.Lang + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| name | string | Yes| Key specified to obtain all key-value pairs.| +| name | string | Yes | Key specified to obtain all key-value pairs. | **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| string[] | All key-value pairs matching the specified key.| +| string[] | All key-value pairs matching the specified key. | **Example** ```js -let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); -let paramsObject = new URLSearchParams(urlObject.search.slice(1)); +let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); paramsObject.append('fod', 3); // Add a second value for the fod parameter. console.log(params.getAll('fod')) // Output ["1","3"]. ``` @@ -117,16 +122,18 @@ entries(): IterableIterator<[string, string]> Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and the first and second fields of each array are the key and value respectively. +**System capability**: SystemCapability.Utils.Lang + **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| IterableIterator<[string, string]> | ES6 iterator.| +| IterableIterator<[string, string]> | ES6 iterator. | **Example** ```js -var searchParamsObject = new URLSearchParams("keyName1=valueName1&keyName2=valueName2"); +var searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs console.log(pair[0]+ ', '+ pair[1]); } @@ -139,25 +146,27 @@ forEach(callbackfn: (value: string, key: string, searchParams: this) => void, th Traverses the key-value pairs in the **URLSearchParams** instance by using a callback. +**System capability**: SystemCapability.Utils.Lang + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| callbackfn | function | Yes| Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance.| -| thisArg | Object | No| Value to use when the callback is invoked.| +| callbackfn | function | Yes | Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance. | +| thisArg | Object | No | Value to use when the callback is invoked. | **Table 1** callbackfn parameter description -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| value | string | Yes| Value that is currently traversed.| -| key | string | Yes| Key that is currently traversed.| -| searchParams | Object | Yes| Instance that invokes the **forEach** method.| +| value | string | Yes | Value that is currently traversed. | +| key | string | Yes | Key that is currently traversed. | +| searchParams | Object | Yes | Instance that invokes the **forEach** method. | **Example** ```js -const myURLObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); +const myURLObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); myURLObject.searchParams.forEach((value, name, searchParams) => { console.log(name, value, myURLObject.searchParams === searchParams); }); @@ -170,23 +179,25 @@ get(name: string): string | null Obtains the value of the first key-value pair based on the specified key. +**System capability**: SystemCapability.Utils.Lang + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| name | string | Yes| Key specified to obtain the value.| +| name | string | Yes | Key specified to obtain the value. | **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| string | Returns the value of the first key-value pair if obtained.| -| null | Returns null if no value is obtained.| +| string | Returns the value of the first key-value pair if obtained. | +| null | Returns null if no value is obtained. | **Example** ```js -var paramsOject = new URLSearchParams(document.location.search.substring(1)); +var paramsOject = new Url.URLSearchParams(document.location.search.substring(1)); var name = paramsOject.get("name"); // is the string "Jonathan" var age = parseInt(paramsOject.get("age"), 10); // is the number 18 var address = paramsOject.get("address"); // null @@ -199,23 +210,25 @@ has(name: string): boolean Checks whether a key has a value. +**System capability**: SystemCapability.Utils.Lang + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| name | string | Yes| Key specified to search for its value.| +| name | string | Yes | Key specified to search for its value. | **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| boolean | Returns **true** if the value exists; returns **false** otherwise.| +| boolean | Returns **true** if the value exists; returns **false** otherwise. | **Example** ```js -let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); -let paramsObject = new URLSearchParams(urlObject.search.slice(1)); +let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); paramsObject.has('bard') === true; ``` @@ -226,18 +239,20 @@ set(name: string, value: string): void Sets the value for a key. If key-value pairs matching the specified key exist, the value of the first key-value pair will be set to the specified value and other key-value pairs will be deleted. Otherwise, the key-value pair will be appended to the query string. +**System capability**: SystemCapability.Utils.Lang + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| name | string | Yes| Key of the value to set.| -| value | string | Yes| Value to set.| +| name | string | Yes | Key of the value to set. | +| value | string | Yes | Value to set. | **Example** ```js -let urlObject = new URL('https://developer.exampleUrl/?fod=1&bard=2'); -let paramsObject = new URLSearchParams(urlObject.search.slice(1)); +let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); +let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); paramsObject.set('baz', 3); // Add a third parameter. ``` @@ -246,13 +261,14 @@ paramsObject.set('baz', 3); // Add a third parameter. sort(): void +Sorts all key-value pairs contained in this object based on the Unicode code points of the keys and returns undefined. This method uses a stable sorting algorithm, that is, the relative order between key-value pairs with equal keys is retained. -Sorts all key-value pairs contained in this object based on the Unicode code points of the keys and returns undefined. This method uses a stable sorting algorithm, that is, the relative order between key-value pairs with equal keys is retained. +**System capability**: SystemCapability.Utils.Lang **Example** ```js -var searchParamsObject = new URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object +var searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object searchParamsObject.sort(); // Sort the key/value pairs console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 ``` @@ -262,19 +278,20 @@ console.log(searchParamsObject.toString()); // Display the sorted query string / keys(): IterableIterator<string> - Obtains an ES6 iterator that contains the keys of all the key-value pairs. +**System capability**: SystemCapability.Utils.Lang + **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| IterableIterator<string> | ES6 iterator that contains the keys of all the key-value pairs.| +| IterableIterator<string> | ES6 iterator that contains the keys of all the key-value pairs. | **Example** ```js -var searchParamsObject = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +var searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing for (var key of searchParamsObject .keys()) { // Output key-value pairs console.log(key); } @@ -287,16 +304,18 @@ values(): IterableIterator<string> Obtains an ES6 iterator that contains the values of all the key-value pairs. +**System capability**: SystemCapability.Utils.Lang + **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| IterableIterator<string> | ES6 iterator that contains the values of all the key-value pairs.| +| IterableIterator<string> | ES6 iterator that contains the values of all the key-value pairs. | **Example** ```js -var searchParams = new URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +var searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing for (var value of searchParams.values()) { console.log(value); } @@ -307,19 +326,20 @@ for (var value of searchParams.values()) { [Symbol.iterator]\(): IterableIterator<[string, string]> - Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and the first and second fields of each array are the key and value respectively. +**System capability**: SystemCapability.Utils.Lang + **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| IterableIterator<[string, string]> | ES6 iterator.| +| IterableIterator<[string, string]> | ES6 iterator. | **Example** ```js -const paramsObject = new URLSearchParams('fod=bay&edg=bap'); +const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap'); for (const [name, value] of paramsObject) { console.log(name, value); } @@ -330,20 +350,21 @@ for (const [name, value] of paramsObject) { toString(): string - Obtains search parameters that are serialized as a string and, if necessary, percent-encodes the characters in the string. +**System capability**: SystemCapability.Utils.Lang + **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| string | String of serialized search parameters, which is percent-encoded if necessary.| +| string | String of serialized search parameters, which is percent-encoded if necessary. | **Example** ```js -let url = new URL('https://developer.exampleUrl/?fod=1&bard=2'); -let params = new URLSearchParams(url.search.slice(1)); +let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); +let params = new Url.URLSearchParams(url.search.slice(1)); params.append('fod', 3); console.log(params.toString()); ``` @@ -351,9 +372,10 @@ console.log(params.toString()); ## URL - ### Attributes +**System capability**: SystemCapability.Utils.Lang + | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | | hash | string | Yes| Yes| String that contains a harsh mark (#) followed by the fragment identifier of a URL.| @@ -374,31 +396,32 @@ console.log(params.toString()); constructor(url: string, base?: string | URL) - Creates a URL. +**System capability**: SystemCapability.Utils.Lang + **Parameters** -| Name| Type| Mandatory| Description| +| Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| url | string | Yes| Input object.| -| base | string \| URL | No| Input parameter, which can be any of the following:
- **string**: string
- **URL**: string or object| +| url | string | Yes | Input object. | +| base | string \ |& URL | No | Input parameter, which can be any of the following:
- **string**: string
- **URL**: string or object | **Example** ```js var mm = 'http://username:password@host:8080'; -var a = new URL("/", mm); // Output 'http://username:password@host:8080/'; -var b = new URL(mm); // Output 'http://username:password@host:8080/'; -new URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; -var c = new URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; -new URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; -new URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; -new URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 -new URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL -new URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL -new URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/ -new URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/ +var a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; +var b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; +new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; +var c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; +new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; +new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; +new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 +new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL +new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL +new Url.URL('http://www.shanxi.com', ); // Output http://www.shanxi.com/ +new Url.URL('http://www.shanxi.com', b); // Output http://www.shanxi.com/ ``` @@ -408,16 +431,18 @@ toString(): string Converts the parsed URL into a string. +**System capability**: SystemCapability.Utils.Lang + **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| string | Website address in a serialized string.| +| string | Website address in a serialized string. | **Example** ```js -const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); +const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); url.toString() ``` @@ -426,17 +451,18 @@ url.toString() toJSON(): string - Converts the parsed URL into a JSON string. +**System capability**: SystemCapability.Utils.Lang + **Return value** -| Type| Description| +| Type | Description | | -------- | -------- | -| string | Website address in a serialized string.| +| string | Website address in a serialized string. | **Example** ```js -const url = new URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); +const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); url.toJSON() -``` +``` \ No newline at end of file diff --git a/en/application-dev/reference/apis/js-apis-util.md b/en/application-dev/reference/apis/js-apis-util.md index ecc46e0c2d..2ac8daeb37 100755 --- a/en/application-dev/reference/apis/js-apis-util.md +++ b/en/application-dev/reference/apis/js-apis-util.md @@ -1,11 +1,12 @@ # util -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> **NOTE** +> > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -This module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **types** for checks of built-in object types. +This module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types. ## Modules to Import @@ -140,7 +141,7 @@ Processes an asynchronous function and returns a promise version. | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| encoding | string | Yes| No| Encoding format.
- Supported formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-8-i, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, koi8-r, koi8-u, macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, x-mac-cyrilli, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis, euc-kr, utf-16be, utf-16le| +| encoding | string | Yes| No| Encoding format.
- Supported formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-8-i, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, koi8-r, koi8-u, macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, x-mac-cyrilli, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis, euc-kr, utf-16be, utf-16le| | fatal | boolean | Yes| No| Whether to display fatal errors.| | ignoreBOM | boolean | Yes| No| Whether to ignore the byte order marker (BOM). The default value is **false**, which indicates that the result contains the BOM.| @@ -208,9 +209,6 @@ Decodes the input content. result[4] = 0x62; result[5] = 0x63; console.log("input num:"); - for(var j= 0; j < 6; j++) { - console.log(result[j]); - } var retStr = textDecoder.decode( result , {stream: false}); console.log("retStr = " + retStr); ``` @@ -262,6 +260,7 @@ Encodes the input content. **Example** ```js var textEncoder = new util.TextEncoder(); + var buffer = new ArrayBuffer(20); var result = new Uint8Array(buffer); result = textEncoder.encode("\uD800¥¥"); ``` @@ -361,7 +360,6 @@ Compares this **RationalNumber** object with a given object. | number | Returns **0** if the two objects are equal; returns **1** if the given object is less than this object; return **-1** if the given object is greater than this object.| **Example** - ```js var rationalNumber = new util.RationalNumber(1,2); var rational = rationalNumer.creatRationalFromString("3/4"); @@ -484,7 +482,7 @@ Obtains the denominator of this **RationalNumber** object. ### isZero8+ -isZero​(): boolean +isZero​():boolean Checks whether this **RationalNumber** object is **0**. @@ -524,7 +522,7 @@ Checks whether this **RationalNumber** object is a Not a Number (NaN). ### isFinite8+ -isFinite​(): boolean +isFinite​():boolean Checks whether this **RationalNumber** object represents a finite value. @@ -825,7 +823,7 @@ Obtains the value of the specified key. **Return value** | Type| Description| | -------- | -------- | -| V \| undefind | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.| +| V \| undefind | Returns the value of the key if a match is found in the buffer; returns **undefined** otherwise.| **Example** ```js @@ -872,7 +870,7 @@ Obtains all values in this buffer, listed from the most to the least recently ac **Return value** | Type| Description| | -------- | -------- | -| V [] | All values in the buffer, listed from the most to the least recently accessed.| +| V [] | All values in the buffer, listed from the most to the least recently accessed.| **Example** ```js @@ -895,7 +893,7 @@ Obtains all keys in this buffer, listed from the most to the least recently acce **Return value** | Type| Description| | -------- | -------- | -| K [] | All keys in the buffer, listed from the most to the least recently accessed.| +| K [] | All keys in the buffer, listed from the most to the least recently accessed.| **Example** ```js @@ -921,7 +919,7 @@ Removes the specified key and its value from this buffer. **Return value** | Type| Description| | -------- | -------- | -| V \| undefind | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.| +| V \| undefind | Returns an **Optional** object containing the removed key-value pair if the key exists in the buffer; returns an empty **Optional** object otherwise. If the key is null, an exception will be thrown.| **Example** ```js @@ -1038,7 +1036,7 @@ Obtains a new iterator object that contains all key-value pairs in this object. **Return value** | Type| Description| | -------- | -------- | -| [K, V] | Iterable array.| +| [K, V] | Iterable array.| **Example** ```js @@ -1059,7 +1057,7 @@ Obtains a two-dimensional array in key-value pairs. **Return value** | Type| Description| | -------- | -------- | -| [K, V] | Two-dimensional array in key-value pairs.| +| [K, V] | Two-dimensional array in key-value pairs.| **Example** ```js @@ -1092,6 +1090,8 @@ Example ```js class Temperature{ constructor(value){ + // If TS is used for development, add the following code: + // private readonly _temp: Temperature; this._temp = value; } comapreTo(value){ @@ -1183,7 +1183,7 @@ Obtains the intersection of this **Scope** and the given **Scope**. ### intersect8+ -intersect(lowerObj: ScopeType,upperObj: ScopeType): Scope +intersect(lowerObj:ScopeType,upperObj:ScopeType):Scope Obtains the intersection of this **Scope** and the given lower and upper limits. @@ -1276,6 +1276,7 @@ Obtains the union set of this **Scope** and the given lower and upper limits. | [Scope](#scope8) | Union set of this **Scope** and the given lower and upper limits.| **Example** + ```js var tempLower = new Temperature(30); var tempUpper = new Temperature(40); @@ -1288,7 +1289,7 @@ Obtains the union set of this **Scope** and the given lower and upper limits. ### expand8+ -expand(range:Scope):Scope +expand(range: Scope): Scope Obtains the union set of this **Scope** and the given **Scope**. @@ -1510,7 +1511,7 @@ Decodes the input content. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| src | Uint8Array \| string | Yes| Uint8Array or string to decode.| +| src | Uint8Array \| string | Yes| Uint8Array or string to decode.| **Return value** | Type| Description| @@ -1595,7 +1596,7 @@ Decodes the input content asynchronously. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.| +| src | Uint8Array \| string | Yes| Uint8Array or string to decode asynchronously.| **Return value** | Type| Description| @@ -1622,7 +1623,7 @@ Decodes the input content asynchronously. constructor() -A constructor used to create a **types** object. +A constructor used to create a **Types** object. **System capability**: SystemCapability.Utils.Lang diff --git a/en/application-dev/reference/apis/js-apis-xml.md b/en/application-dev/reference/apis/js-apis-xml.md index 124d845c0e..1175651b96 100644 --- a/en/application-dev/reference/apis/js-apis-xml.md +++ b/en/application-dev/reference/apis/js-apis-xml.md @@ -1,6 +1,7 @@ # XML Parsing and Generation -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> **NOTE** +> > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -10,10 +11,6 @@ import xml from '@ohos.xml'; ``` -## System Capabilities - -SystemCapability.Utils.Lang - ## XmlSerializer @@ -23,11 +20,13 @@ constructor(buffer: ArrayBuffer | DataView, encoding?: string) A constructor used to create an **XmlSerializer** instance. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| buffer | ArrayBuffer \| DataView | Yes| **ArrayBuffer** or **DataView** for storing the XML information to write.| +| buffer | ArrayBuffer \| DataView | Yes| **ArrayBuffer** or **DataView** for storing the XML information to write.| | encoding | string | No| Encoding format.| **Example** @@ -45,6 +44,8 @@ setAttributes(name: string, value: string): void Sets an attribute. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -55,6 +56,8 @@ Sets an attribute. **Example** ```js +var arrayBuffer = new ArrayBuffer(1024); +var bufView = new DataView(arrayBuffer); var thatSer = new xml.XmlSerializer(bufView); thatSer.setAttributes("importance", "high"); ``` @@ -66,6 +69,8 @@ addEmptyElement(name: string): void Adds an empty element. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -75,6 +80,8 @@ Adds an empty element. **Example** ```js +var arrayBuffer = new ArrayBuffer(1024); +var bufView = new DataView(arrayBuffer); var thatSer = new xml.XmlSerializer(bufView); thatSer.addEmptyElement("b"); // => ``` @@ -86,9 +93,13 @@ setDeclaration(): void Sets a declaration. +**System capability**: SystemCapability.Utils.Lang + **Example** ```js +var arrayBuffer = new ArrayBuffer(1024); +var bufView = new DataView(arrayBuffer); var thatSer = new xml.XmlSerializer(bufView); thatSer.setDeclaration() // => ; ``` @@ -100,6 +111,8 @@ startElement(name: string): void Writes the start tag based on the given element name. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -122,9 +135,13 @@ endElement(): void Writes the end tag of the element. +**System capability**: SystemCapability.Utils.Lang + **Example** ```js +var arrayBuffer = new ArrayBuffer(1024); +var bufView = new DataView(arrayBuffer); var thatSer = new xml.XmlSerializer(bufView); thatSer.setNamespace("h", "http://www.w3.org/TR/html4/"); thatSer.startElement("table"); @@ -140,6 +157,8 @@ setNamespace(prefix: string, namespace: string): void Sets the namespace for an element tag. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -164,6 +183,8 @@ setComment(text: string): void Sets the comment. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -187,6 +208,8 @@ setCDATA(text: string): void Sets CDATA attributes. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -208,6 +231,8 @@ setText(text: string): void Sets **Text**. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -232,6 +257,8 @@ setDocType(text: string): void Sets **DocType**. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -256,11 +283,13 @@ constructor(buffer: ArrayBuffer | DataView, encoding?: string) Creates and returns an **XmlPullParser** object. The **XmlPullParser** object passes two parameters. The first parameter is the memory of the **ArrayBuffer** or **DataView** type, and the second parameter is the file format (UTF-8 by default). +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| buffer | ArrayBuffer \| DataView | Yes| **ArrayBuffer** or **DataView** that contains XML text information.| +| buffer | ArrayBuffer \| DataView | Yes| **ArrayBuffer** or **DataView** that contains XML text information.| | encoding | string | No| Encoding format. Only UTF-8 is supported.| **Example** @@ -289,6 +318,8 @@ parse(option: ParseOptions): void Parses XML information. +**System capability**: SystemCapability.Utils.Lang + **Parameters** | Name| Type| Mandatory| Description| @@ -329,14 +360,16 @@ that.parse(options); Defines the XML parsing options. +**System capability**: SystemCapability.Utils.Lang + | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | supportDoctype | boolean | No| Whether to ignore **Doctype**. The default value is **false**.| | ignoreNameSpace | boolean | No| Whether to ignore **Namespace**. The default value is **false**.| -| tagValueCallbackFunction | (name: string, value: string)=> boolean | No| Callback used to return **tagValue**.| -| attributeValueCallbackFunction | (name: string, value: string)=> boolean | No| Callback used to return **attributeValue**.| -| tokenValueCallbackFunction | (eventType: [EventType](#eventtype), value: [ParseInfo](#parseinfo))=> boolean | No| Callback used to return **tokenValue**.| +| tagValueCallbackFunction | (name: string, value: string)=> boolean | No| Callback used to return **tagValue**.| +| attributeValueCallbackFunction | (name: string, value: string)=> boolean | No| Callback used to return **attributeValue**.| +| tokenValueCallbackFunction | (eventType: [EventType](#eventtype), value: [ParseInfo](#parseinfo))=> boolean | No| Callback used to return **tokenValue**.| ## ParseInfo @@ -349,6 +382,8 @@ getColumnNumber(): number Obtains the column line number, which starts from 1. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -362,6 +397,8 @@ getDepth(): number Obtains the depth of this element. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -375,6 +412,8 @@ getLineNumber(): number Obtains the current line number, starting from 1. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -388,6 +427,8 @@ getName(): string Obtains the name of this element. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -401,6 +442,8 @@ getNamespace(): string Obtains the namespace of this element. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -414,6 +457,8 @@ getPrefix(): string Obtains the prefix of this element. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -427,6 +472,8 @@ getText(): string Obtains the text of the current event. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -440,6 +487,8 @@ isEmptyElementTag(): boolean Checks whether the current element is empty. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -453,6 +502,8 @@ isWhitespace(): boolean Checks whether the current text event contains only whitespace characters. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| @@ -466,6 +517,8 @@ getAttributeCount(): number Obtains the number of attributes for the current start tag. +**System capability**: SystemCapability.Utils.Lang + **Return value** | Type| Description| | -------- | -------- | @@ -476,6 +529,8 @@ Obtains the number of attributes for the current start tag. Enumerates the events. +**System capability**: SystemCapability.Utils.Lang + | Name| Value| Description| | -------- | -------- | -------- | | START_DOCUMENT | 0 | Indicates a start document event.| -- GitLab