提交 7eafa641 编写于 作者: W wusongqing

update docs against 5768

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 d35878b6
# URL String Parsing
> **NOTE**<br>
> **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.
......@@ -25,16 +26,16 @@ Creates a **URLSearchParams** instance.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| init | string[][]&nbsp;\|&nbsp;Record&lt;string,&nbsp;string&gt;&nbsp;\|&nbsp;string&nbsp;\|&nbsp;URLSearchParams | No| Input parameter objects, which include the following:<br>- **string[][]**: two-dimensional string array<br>-&nbsp;**Record&lt;string,&nbsp;string&gt;**: list of objects<br>- **string**: string<br>- **URLSearchParams**: object |
| init | string[][] \| Record&lt;string, string&gt; \| string \| URLSearchParams | No| Input parameter objects, which include the following:<br>- **string[][]**: two-dimensional string array<br>- **Record&lt;string, string&gt;**: list of objects<br>- **string**: string<br>- **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);
```
......@@ -48,16 +49,16 @@ Appends a key-value pair into the query string.
**Parameters**
| 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 | 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. |
**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);
```
......@@ -72,15 +73,15 @@ Deletes key-value pairs of the specified key.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Key of the key-value pairs to delete. |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| 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');
```
......@@ -95,21 +96,21 @@ Obtains all the key-value pairs based on the specified key.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Key specified to obtain all key-value pairs. |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Key specified to obtain all key-value pairs. |
**Return value**
| Type | Description |
| -------- | -------- |
| string[] | All key-value pairs matching the specified key. |
| Type | Description |
| -------- | -------- |
| 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"].
```
......@@ -125,14 +126,14 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
**Return value**
| Type | Description |
| -------- | -------- |
| IterableIterator&lt;[string,&nbsp;string]&gt; | ES6 iterator. |
| Type | Description |
| -------- | -------- |
| IterableIterator&lt;[string, string]&gt; | 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]);
}
......@@ -149,23 +150,23 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal
**Parameters**
| 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. |
| 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. |
**Table 1** callbackfn parameter 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. |
| 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. |
**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);
});
......@@ -182,21 +183,21 @@ Obtains the value of the first key-value pair based on the specified key.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Key specified to obtain the value. |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Key specified to obtain the value. |
**Return value**
| Type | Description |
| -------- | -------- |
| string | Returns the value of the first key-value pair if obtained. |
| null | Returns null if no value is obtained. |
| Type | Description |
| -------- | -------- |
| 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
......@@ -213,21 +214,21 @@ Checks whether a key has a value.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Key specified to search for its value. |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Key specified to search for its value. |
**Return value**
| Type | Description |
| -------- | -------- |
| boolean | Returns **true** if the value exists; returns **false** otherwise. |
| Type | Description |
| -------- | -------- |
| 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;
```
......@@ -242,16 +243,16 @@ Sets the value for a key. If key-value pairs matching the specified key exist, t
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| name | string | Yes | Key of the value to set. |
| value | string | Yes | Value to set. |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| 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.
```
......@@ -267,7 +268,7 @@ Sorts all key-value pairs contained in this object based on the Unicode code poi
**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
```
......@@ -283,14 +284,14 @@ Obtains an ES6 iterator that contains the keys of all the key-value pairs.
**Return value**
| Type | Description |
| -------- | -------- |
| IterableIterator&lt;string&gt; | ES6 iterator that contains the keys of all the key-value pairs. |
| Type | Description |
| -------- | -------- |
| IterableIterator&lt;string&gt; | 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);
}
......@@ -307,14 +308,14 @@ Obtains an ES6 iterator that contains the values of all the key-value pairs.
**Return value**
| Type | Description |
| -------- | -------- |
| IterableIterator&lt;string&gt; | ES6 iterator that contains the values of all the key-value pairs. |
| Type | Description |
| -------- | -------- |
| IterableIterator&lt;string&gt; | 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);
}
......@@ -331,14 +332,14 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
**Return value**
| Type | Description |
| -------- | -------- |
| IterableIterator&lt;[string,&nbsp;string]&gt; | ES6 iterator. |
| Type | Description |
| -------- | -------- |
| IterableIterator&lt;[string, string]&gt; | 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);
}
......@@ -355,15 +356,15 @@ Obtains search parameters that are serialized as a string and, if necessary, per
**Return value**
| Type | Description |
| -------- | -------- |
| string | String of serialized search parameters, which is percent-encoded if necessary. |
| Type | Description |
| -------- | -------- |
| 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());
```
......@@ -401,26 +402,26 @@ Creates a URL.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| url | string | Yes | Input object. |
| base | string&nbsp;\ |&nbsp;URL | No | Input parameter, which can be any of the following:<br>- **string**: string<br>- **URL**: string or object |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| url | string | Yes | Input object. |
| base | string \ |& URL | No | Input parameter, which can be any of the following:<br>- **string**: string<br>- **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/
```
......@@ -434,14 +435,14 @@ Converts the parsed URL into a string.
**Return value**
| Type | Description |
| -------- | -------- |
| string | Website address in a serialized string. |
| Type | Description |
| -------- | -------- |
| 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()
```
......@@ -456,12 +457,12 @@ Converts the parsed URL into a JSON string.
**Return value**
| Type | Description |
| -------- | -------- |
| string | Website address in a serialized string. |
| Type | Description |
| -------- | -------- |
| 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
# XML Parsing and Generation
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> **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.
......@@ -25,7 +26,7 @@ A constructor used to create an **XmlSerializer** instance.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buffer | ArrayBuffer&nbsp;\|&nbsp;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**
......@@ -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");
```
......@@ -77,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"); // => <b/>
```
......@@ -93,6 +98,8 @@ Sets a declaration.
**Example**
```js
var arrayBuffer = new ArrayBuffer(1024);
var bufView = new DataView(arrayBuffer);
var thatSer = new xml.XmlSerializer(bufView);
thatSer.setDeclaration() // => <?xml version="1.0" encoding="utf-8"?>;
```
......@@ -133,6 +140,8 @@ Writes the end tag of the element.
**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");
......@@ -280,7 +289,7 @@ Creates and returns an **XmlPullParser** object. The **XmlPullParser** object pa
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buffer | ArrayBuffer&nbsp;\|&nbsp;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**
......@@ -358,9 +367,9 @@ Defines the XML parsing options.
| -------- | -------- | -------- | -------- |
| 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:&nbsp;string,&nbsp;value:&nbsp;string)=&gt;&nbsp;boolean | No| Callback used to return **tagValue**.|
| attributeValueCallbackFunction | (name:&nbsp;string,&nbsp;value:&nbsp;string)=&gt;&nbsp;boolean | No| Callback used to return **attributeValue**.|
| tokenValueCallbackFunction | (eventType:&nbsp;[EventType](#eventtype),&nbsp;value:&nbsp;[ParseInfo](#parseinfo))=&gt;&nbsp;boolean | No| Callback used to return **tokenValue**.|
| tagValueCallbackFunction | (name: string, value: string)=&gt; boolean | No| Callback used to return **tagValue**.|
| attributeValueCallbackFunction | (name: string, value: string)=&gt; boolean | No| Callback used to return **attributeValue**.|
| tokenValueCallbackFunction | (eventType: [EventType](#eventtype), value: [ParseInfo](#parseinfo))=&gt; boolean | No| Callback used to return **tokenValue**.|
## ParseInfo
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册