未验证 提交 89d964ec 编写于 作者: O openharmony_ci 提交者: Gitee

!23989 公共库代码适配ArkTs

Merge pull request !23989 from jiangkai/master
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
## 导入模块 ## 导入模块
```js ```ts
import convertxml from '@ohos.convertxml'; import convertxml from '@ohos.convertxml';
``` ```
...@@ -46,7 +46,7 @@ convertToJSObject(xml: string, options?: ConvertOptions) : Object ...@@ -46,7 +46,7 @@ convertToJSObject(xml: string, options?: ConvertOptions) : Object
**示例:** **示例:**
```js ```ts
try { try {
let xml = let xml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -56,7 +56,7 @@ try { ...@@ -56,7 +56,7 @@ try {
' <todo>Play</todo>' + ' <todo>Play</todo>' +
'</note>'; '</note>';
let conv = new convertxml.ConvertXML() let conv = new convertxml.ConvertXML()
let options = { let options: convertxml.ConvertOptions = {
trim: false, declarationKey: "_declaration", trim: false, declarationKey: "_declaration",
instructionKey: "_instruction", attributesKey: "_attributes", instructionKey: "_instruction", attributesKey: "_attributes",
textKey: "_text", cdataKey: "_cdata", doctypeKey: "_doctype", textKey: "_text", cdataKey: "_cdata", doctypeKey: "_doctype",
...@@ -99,7 +99,7 @@ convert(xml: string, options?: ConvertOptions) : Object ...@@ -99,7 +99,7 @@ convert(xml: string, options?: ConvertOptions) : Object
**示例:** **示例:**
```js ```ts
let xml = let xml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' + '<note importance="high" logged="true">' +
...@@ -108,7 +108,7 @@ let xml = ...@@ -108,7 +108,7 @@ let xml =
' <todo>Play</todo>' + ' <todo>Play</todo>' +
'</note>'; '</note>';
let conv = new convertxml.ConvertXML(); let conv = new convertxml.ConvertXML();
let options = {trim : false, declarationKey:"_declaration", let options: convertxml.ConvertOptions = {trim : false, declarationKey:"_declaration",
instructionKey : "_instruction", attributesKey : "_attributes", instructionKey : "_instruction", attributesKey : "_attributes",
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype", textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
commentKey : "_comment", parentKey : "_parent", typeKey : "_type", commentKey : "_comment", parentKey : "_parent", typeKey : "_type",
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
## 导入模块 ## 导入模块
```js ```ts
import uri from '@ohos.uri' import uri from '@ohos.uri'
``` ```
...@@ -47,7 +47,7 @@ import uri from '@ohos.uri' ...@@ -47,7 +47,7 @@ import uri from '@ohos.uri'
**URI示例:** **URI示例:**
```js ```ts
const result1 = new uri.URI("ftp://ftp.aaa.bbb.ccc/dddd/eee.txt"); const result1 = new uri.URI("ftp://ftp.aaa.bbb.ccc/dddd/eee.txt");
console.log(result1.host) // ftp.aaa.bbb.ccc console.log(result1.host) // ftp.aaa.bbb.ccc
console.log(result1.fragment) // null console.log(result1.fragment) // null
...@@ -118,12 +118,12 @@ constructor是URI的构造函数。 ...@@ -118,12 +118,12 @@ constructor是URI的构造函数。
**示例:** **示例:**
```js ```ts
let mm = 'https://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; let mm = 'https://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
new uri.URI(mm); // Output 'https://username:password@host:8080/directory/file?foo=1&bar=2#fragment'; new uri.URI(mm);
``` ```
```js ```ts
new uri.URI('https://username:password@host:8080'); // Output 'https://username:password@host:8080'; new uri.URI('https://username:password@host:8080');
``` ```
...@@ -143,7 +143,7 @@ toString(): string ...@@ -143,7 +143,7 @@ toString(): string
**示例:** **示例:**
```js ```ts
const result = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const result = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
let result1 = result.toString(); let result1 = result.toString();
``` ```
...@@ -175,7 +175,7 @@ equals(other: URI): boolean ...@@ -175,7 +175,7 @@ equals(other: URI): boolean
**示例:** **示例:**
```js ```ts
const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
uriInstance.equals(uriInstance1); uriInstance.equals(uriInstance1);
...@@ -202,7 +202,7 @@ equalsTo(other: URI): boolean ...@@ -202,7 +202,7 @@ equalsTo(other: URI): boolean
**示例:** **示例:**
```js ```ts
const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
let result = uriInstance.equalsTo(uriInstance1); let result = uriInstance.equalsTo(uriInstance1);
...@@ -224,7 +224,7 @@ checkIsAbsolute(): boolean ...@@ -224,7 +224,7 @@ checkIsAbsolute(): boolean
**示例:** **示例:**
```js ```ts
const uriInstance = new uri.URI('https://username:password@www.qwer.com:8080?query=pppppp'); const uriInstance = new uri.URI('https://username:password@www.qwer.com:8080?query=pppppp');
console.log(`${uriInstance.checkIsAbsolute()}`); // true console.log(`${uriInstance.checkIsAbsolute()}`); // true
const uriInstance1 = new uri.URI('xxx.com/suppliers.htm'); const uriInstance1 = new uri.URI('xxx.com/suppliers.htm');
...@@ -248,7 +248,7 @@ normalize(): URI ...@@ -248,7 +248,7 @@ normalize(): URI
**示例:** **示例:**
```js ```ts
const uriInstance = new uri.URI('https://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp'); const uriInstance = new uri.URI('https://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp');
console.log(uriInstance.path); // /path/path1/../path2/./path3 console.log(uriInstance.path); // /path/path1/../path2/./path3
let uriInstance1 = uriInstance.normalize(); let uriInstance1 = uriInstance.normalize();
......
...@@ -27,7 +27,7 @@ URLParams的构造函数。 ...@@ -27,7 +27,7 @@ URLParams的构造函数。
**示例:** **示例:**
```js ```ts
let objectParams = new Url.URLParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); let objectParams = new Url.URLParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
let objectParams1 = new Url.URLParams({"fod" : '1' , "bard" : '2'}); let objectParams1 = new Url.URLParams({"fod" : '1' , "bard" : '2'});
let objectParams2 = new Url.URLParams('?fod=1&bard=2'); let objectParams2 = new Url.URLParams('?fod=1&bard=2');
...@@ -53,7 +53,7 @@ append(name: string, value: string): void ...@@ -53,7 +53,7 @@ append(name: string, value: string): void
**示例:** **示例:**
```js ```ts
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1)); let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.append('fod', '3'); paramsObject.append('fod', '3');
...@@ -76,7 +76,7 @@ delete(name: string): void ...@@ -76,7 +76,7 @@ delete(name: string): void
**示例:** **示例:**
```js ```ts
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1)); let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.delete('fod'); paramsObject.delete('fod');
...@@ -105,7 +105,7 @@ getAll(name: string): string[] ...@@ -105,7 +105,7 @@ getAll(name: string): string[]
**示例:** **示例:**
```js ```ts
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLParams(urlObject.search.slice(1)); let params = new Url.URLParams(urlObject.search.slice(1));
params.append('fod', '3'); // Add a second value for the fod parameter. params.append('fod', '3'); // Add a second value for the fod parameter.
...@@ -129,9 +129,11 @@ entries(): IterableIterator<[string, string]> ...@@ -129,9 +129,11 @@ entries(): IterableIterator<[string, string]>
**示例:** **示例:**
```js ```ts
let searchParamsObject = new Url.URLParams("keyName1=valueName1&keyName2=valueName2"); let searchParamsObject = new Url.URLParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject.entries()) { // Show keyName/valueName pairs let pair:Iterable<Object[]> = searchParamsObject.entries();
let arrayValue = Array.from(pair);
for (let pair of arrayValue) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]); console.log(pair[0]+ ', '+ pair[1]);
} }
``` ```
...@@ -162,7 +164,7 @@ forEach(callbackFn: (value: string, key: string, searchParams: this) => void, th ...@@ -162,7 +164,7 @@ forEach(callbackFn: (value: string, key: string, searchParams: this) => void, th
**示例:** **示例:**
```js ```ts
const myURLObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2'); const myURLObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
myURLObject.params.forEach((value, name, searchParams) => { myURLObject.params.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.params === searchParams); console.log(name, value, myURLObject.params === searchParams);
...@@ -193,10 +195,10 @@ get(name: string): string | null ...@@ -193,10 +195,10 @@ get(name: string): string | null
**示例:** **示例:**
```js ```ts
let paramsObject = new Url.URLParams('name=Jonathan&age=18'); let paramsObject = new Url.URLParams('name=Jonathan&age=18');
let name = paramsObject.get("name"); // is the string "Jonathan" let name = paramsObject.get("name"); // is the string "Jonathan"
let age = parseInt(paramsObject.get("age"), 10); // is the number 18 let age = paramsObject.get("age"); // is the string "18"
``` ```
...@@ -222,7 +224,7 @@ has(name: string): boolean ...@@ -222,7 +224,7 @@ has(name: string): boolean
**示例:** **示例:**
```js ```ts
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1)); let paramsObject = new Url.URLParams(urlObject.search.slice(1));
let result = paramsObject.has('bard'); let result = paramsObject.has('bard');
...@@ -246,7 +248,7 @@ set(name: string, value: string): void ...@@ -246,7 +248,7 @@ set(name: string, value: string): void
**示例:** **示例:**
```js ```ts
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1)); let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.set('baz', '3'); // Add a third parameter. paramsObject.set('baz', '3'); // Add a third parameter.
...@@ -263,10 +265,10 @@ sort(): void ...@@ -263,10 +265,10 @@ sort(): void
**示例:** **示例:**
```js ```ts
let searchParamsObject = new Url.URLParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object let searchParamsObject = new Url.URLParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object
searchParamsObject.sort(); // Sort the key/value pairs 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 console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=4&c=3&d=2
``` ```
...@@ -286,9 +288,10 @@ keys(): IterableIterator&lt;string&gt; ...@@ -286,9 +288,10 @@ keys(): IterableIterator&lt;string&gt;
**示例:** **示例:**
```js ```ts
let searchParamsObject = new Url.URLParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing let searchParamsObject = new Url.URLParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var key of searchParamsObject .keys()) { // Output key-value pairs let keys = Array.from(searchParamsObject.keys());
for (let key of keys) { // Output key-value pairs
console.log(key); console.log(key);
} }
``` ```
...@@ -310,9 +313,10 @@ values(): IterableIterator&lt;string&gt; ...@@ -310,9 +313,10 @@ values(): IterableIterator&lt;string&gt;
**示例:** **示例:**
```js ```ts
let searchParams = new Url.URLParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing let searchParams = new Url.URLParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var value of searchParams.values()) { let values = Array.from(searchParams.values());
for (let value of values) {
console.log(value); console.log(value);
} }
``` ```
...@@ -334,10 +338,12 @@ for (var value of searchParams.values()) { ...@@ -334,10 +338,12 @@ for (var value of searchParams.values()) {
**示例:** **示例:**
```js ```ts
const paramsObject = new Url.URLParams('fod=bay&edg=bap'); const paramsObject = new Url.URLParams('fod=bay&edg=bap');
for (const [name, value] of paramsObject[Symbol.iterator]()) { let iter: Iterable<Object[]> = paramsObject[Symbol.iterator]();
console.log(name, value); let pairs = Array.from(iter);
for (let pair of pairs) {
console.log(pair[0] + ', ' + pair[1]);
} }
``` ```
...@@ -358,7 +364,7 @@ toString(): string ...@@ -358,7 +364,7 @@ toString(): string
**示例:** **示例:**
```js ```ts
let url = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2'); let url = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLParams(url.search.slice(1)); let params = new Url.URLParams(url.search.slice(1));
params.append('fod', '3'); params.append('fod', '3');
...@@ -408,7 +414,7 @@ URL的构造函数。 ...@@ -408,7 +414,7 @@ URL的构造函数。
**示例:** **示例:**
```js ```ts
let mm = 'https://username:password@host:8080'; let mm = 'https://username:password@host:8080';
let a = new Url.URL("/", mm); // Output 'https://username:password@host:8080/'; let a = new Url.URL("/", mm); // Output 'https://username:password@host:8080/';
let b = new Url.URL(mm); // Output 'https://username:password@host:8080/'; let b = new Url.URL(mm); // Output 'https://username:password@host:8080/';
...@@ -457,7 +463,7 @@ URL静态成员函数。 ...@@ -457,7 +463,7 @@ URL静态成员函数。
**示例:** **示例:**
```js ```ts
let mm = 'https://username:password@host:8080'; let mm = 'https://username:password@host:8080';
let url = Url.URL.parseURL(mm); let url = Url.URL.parseURL(mm);
let result = url.toString(); // Output 'https://username:password@host:8080/' let result = url.toString(); // Output 'https://username:password@host:8080/'
...@@ -479,7 +485,7 @@ toString(): string ...@@ -479,7 +485,7 @@ toString(): string
**示例:** **示例:**
```js ```ts
const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
let result = url.toString(); let result = url.toString();
``` ```
...@@ -499,7 +505,7 @@ toJSON(): string ...@@ -499,7 +505,7 @@ toJSON(): string
| string | 用于返回网址的字符串序列化。 | | string | 用于返回网址的字符串序列化。 |
**示例:** **示例:**
```js ```ts
const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
let result = url.toJSON(); let result = url.toJSON();
``` ```
...@@ -526,7 +532,7 @@ URLSearchParams的构造函数。 ...@@ -526,7 +532,7 @@ URLSearchParams的构造函数。
**示例:** **示例:**
```js ```ts
let objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); let objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
let objectParams1 = new Url.URLSearchParams({"fod" : '1' , "bard" : '2'}); let objectParams1 = new Url.URLSearchParams({"fod" : '1' , "bard" : '2'});
let objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); let objectParams2 = new Url.URLSearchParams('?fod=1&bard=2');
...@@ -555,7 +561,7 @@ append(name: string, value: string): void ...@@ -555,7 +561,7 @@ append(name: string, value: string): void
**示例:** **示例:**
```js ```ts
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.append('fod', '3'); paramsObject.append('fod', '3');
...@@ -581,7 +587,7 @@ delete(name: string): void ...@@ -581,7 +587,7 @@ delete(name: string): void
**示例:** **示例:**
```js ```ts
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsobject = new Url.URLSearchParams(urlObject.search.slice(1)); let paramsobject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsobject.delete('fod'); paramsobject.delete('fod');
...@@ -613,7 +619,7 @@ getAll(name: string): string[] ...@@ -613,7 +619,7 @@ getAll(name: string): string[]
**示例:** **示例:**
```js ```ts
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLSearchParams(urlObject.search.slice(1)); let params = new Url.URLSearchParams(urlObject.search.slice(1));
params.append('fod', '3'); // Add a second value for the fod parameter. params.append('fod', '3'); // Add a second value for the fod parameter.
...@@ -640,9 +646,11 @@ entries(): IterableIterator<[string, string]> ...@@ -640,9 +646,11 @@ entries(): IterableIterator<[string, string]>
**示例:** **示例:**
```js ```ts
let searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); let searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject.entries()) { // Show keyName/valueName pairs let iter: Iterable<Object[]> = searchParamsObject.entries();
let pairs = Array.from(iter);
for (let pair of pairs) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]); console.log(pair[0]+ ', '+ pair[1]);
} }
``` ```
...@@ -677,7 +685,7 @@ forEach(callbackFn: (value: string, key: string, searchParams: this) => void, th ...@@ -677,7 +685,7 @@ forEach(callbackFn: (value: string, key: string, searchParams: this) => void, th
**示例:** **示例:**
```js ```ts
const myURLObject = new Url.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) => { myURLObject.searchParams.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.searchParams === searchParams); console.log(name, value, myURLObject.searchParams === searchParams);
...@@ -712,10 +720,10 @@ get(name: string): string | null ...@@ -712,10 +720,10 @@ get(name: string): string | null
**示例:** **示例:**
```js ```ts
let paramsObject = new Url.URLSearchParams('name=Jonathan&age=18'); let paramsObject = new Url.URLSearchParams('name=Jonathan&age=18');
let name = paramsObject.get("name"); // is the string "Jonathan" let name = paramsObject.get("name"); // is the string "Jonathan"
let age = parseInt(paramsObject.get("age"), 10); // is the number 18 let age = paramsObject.get("age"); // is the string '18'
``` ```
...@@ -745,7 +753,7 @@ has(name: string): boolean ...@@ -745,7 +753,7 @@ has(name: string): boolean
**示例:** **示例:**
```js ```ts
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.has('bard') === true; paramsObject.has('bard') === true;
...@@ -773,7 +781,7 @@ set(name: string, value: string): void ...@@ -773,7 +781,7 @@ set(name: string, value: string): void
**示例:** **示例:**
```js ```ts
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1));
paramsObject.set('baz', '3'); // Add a third parameter. paramsObject.set('baz', '3'); // Add a third parameter.
...@@ -794,10 +802,10 @@ sort(): void ...@@ -794,10 +802,10 @@ sort(): void
**示例:** **示例:**
```js ```ts
let searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object let searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object
searchParamsObject.sort(); // Sort the key/value pairs 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 console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=4&c=3&d=2
``` ```
...@@ -821,9 +829,10 @@ keys(): IterableIterator&lt;string&gt; ...@@ -821,9 +829,10 @@ keys(): IterableIterator&lt;string&gt;
**示例:** **示例:**
```js ```ts
let searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing let searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var key of searchParamsObject .keys()) { // Output key-value pairs let keys = Array.from(searchParamsObject.keys());
for (let key of keys) { // Output key-value pairs
console.log(key); console.log(key);
} }
``` ```
...@@ -849,9 +858,10 @@ values(): IterableIterator&lt;string&gt; ...@@ -849,9 +858,10 @@ values(): IterableIterator&lt;string&gt;
**示例:** **示例:**
```js ```ts
let searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing let searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing
for (var value of searchParams.values()) { let values = Array.from(searchParams.values());
for (let value of values) {
console.log(value); console.log(value);
} }
``` ```
...@@ -877,10 +887,12 @@ for (var value of searchParams.values()) { ...@@ -877,10 +887,12 @@ for (var value of searchParams.values()) {
**示例:** **示例:**
```js ```ts
const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap'); const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap');
for (const [name, value] of paramsObject) { let iter: Iterable<Object[]> = paramsObject[Symbol.iterator]();
console.log(name, value); let pairs = Array.from(iter);
for (let pair of pairs) {
console.log(pair[0] + ', ' + pair[1]);
} }
``` ```
...@@ -904,7 +916,7 @@ toString(): string ...@@ -904,7 +916,7 @@ toString(): string
**示例:** **示例:**
```js ```ts
let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLSearchParams(url.search.slice(1)); let params = new Url.URLSearchParams(url.search.slice(1));
params.append('fod', '3'); params.append('fod', '3');
......
...@@ -30,7 +30,7 @@ XmlSerializer的构造函数。 ...@@ -30,7 +30,7 @@ XmlSerializer的构造函数。
**示例:** **示例:**
```js ```ts
let arrayBuffer = new ArrayBuffer(2048); let arrayBuffer = new ArrayBuffer(2048);
let thatSer = new xml.XmlSerializer(arrayBuffer, "utf-8"); let thatSer = new xml.XmlSerializer(arrayBuffer, "utf-8");
thatSer.setDeclaration(); thatSer.setDeclaration();
...@@ -61,7 +61,7 @@ setAttributes(name: string, value: string): void ...@@ -61,7 +61,7 @@ setAttributes(name: string, value: string): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -94,7 +94,7 @@ addEmptyElement(name: string): void ...@@ -94,7 +94,7 @@ addEmptyElement(name: string): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -119,7 +119,7 @@ setDeclaration(): void ...@@ -119,7 +119,7 @@ setDeclaration(): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -153,7 +153,7 @@ startElement(name: string): void ...@@ -153,7 +153,7 @@ startElement(name: string): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -180,7 +180,7 @@ endElement(): void ...@@ -180,7 +180,7 @@ endElement(): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -215,7 +215,7 @@ setNamespace(prefix: string, namespace: string): void ...@@ -215,7 +215,7 @@ setNamespace(prefix: string, namespace: string): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -248,7 +248,7 @@ setComment(text: string): void ...@@ -248,7 +248,7 @@ setComment(text: string): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -279,7 +279,7 @@ setCDATA(text: string): void ...@@ -279,7 +279,7 @@ setCDATA(text: string): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -310,7 +310,7 @@ setText(text: string): void ...@@ -310,7 +310,7 @@ setText(text: string): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -344,7 +344,7 @@ setDocType(text: string): void ...@@ -344,7 +344,7 @@ setDocType(text: string): void
**示例:** **示例:**
```js ```ts
const myMAX = 2048; const myMAX = 2048;
let arrayBuffer = new ArrayBuffer(myMAX); let arrayBuffer = new ArrayBuffer(myMAX);
let thatSer = new xml.XmlSerializer(arrayBuffer); let thatSer = new xml.XmlSerializer(arrayBuffer);
...@@ -379,7 +379,7 @@ constructor(buffer: ArrayBuffer | DataView, encoding?: string) ...@@ -379,7 +379,7 @@ constructor(buffer: ArrayBuffer | DataView, encoding?: string)
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -405,13 +405,14 @@ let textEncoder = new util.TextEncoder(); ...@@ -405,13 +405,14 @@ let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer, 'UTF-8'); let that = new xml.XmlPullParser(arrbuffer.buffer, 'UTF-8');
let str1 = ''; let str1 = '';
function func1(name, value){ function func1(name: string, value: string) {
str1 += name+':'+value; str1 += name + value;
return true; return true;
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tagValueCallbackFunction:func1} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tagValueCallbackFunction:func1}
that.parse(options); that.parse(options);
console.log(str1) //'note:company:title:title:lens:lens:a:b:h:table:h:tr:h:td:h:td:' console.log(str1)
// note [<!ENTITY foo "baa">]note funcrion matchwo(a,6){return 1;} Hello, World! companyJohn amp;amp; Hanscompany titleHappytitle titleHappytitle lensWorklens lensPlaylens go there abba h:table h:tr h:tdApplesh:td h:tdBananash:td h:tr h:tablenote
``` ```
...@@ -431,7 +432,7 @@ parse(option: ParseOptions): void ...@@ -431,7 +432,7 @@ parse(option: ParseOptions): void
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -443,20 +444,16 @@ let strXml = ...@@ -443,20 +444,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.getDepth() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getDepth();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:0key:2 value:1key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:3 value:1key:1 value:0 // key:0 value:0 key:2 value:1 key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 key:3 value:1 key:1 value:0
// 解析: // 解析:
// key代表了当前事件类型,value为当前解析的深度。你可以根据EVENTTYPE来知道具体的解析事件。例如本示例结果key: value代表含义为: // key代表了当前事件类型,value为当前解析的深度。你可以根据EVENTTYPE来知道具体的解析事件。例如本示例结果key: value代表含义为:
// 0(START_DOCUMENT):0(起始深度为0), 2(START_TAG):1(解析到开始标签node, 对应深度为1), 10(WHITESPACE):1(解析到空白标签空格, 对应深度为1), 2(START_TAG):2(解析到开始标签title, 对应深度为2), ... // 0(START_DOCUMENT):0(起始深度为0), 2(START_TAG):1(解析到开始标签node, 对应深度为1), 10(WHITESPACE):1(解析到空白标签空格, 对应深度为1), 2(START_TAG):2(解析到开始标签title, 对应深度为2), ...
...@@ -499,7 +496,7 @@ getColumnNumber(): number ...@@ -499,7 +496,7 @@ getColumnNumber(): number
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -511,20 +508,16 @@ let strXml = ...@@ -511,20 +508,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.getColumnNumber() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getColumnNumber();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:1key:2 value:77key:10 value:81key:2 value:88key:4 value:93key:3 value:101key:10 value:105key:2 value:111key:4 value:115key:3 value:122key:10 value:126key:2 value:132key:4 value:136key:3 value:143key:3 value:150key:1 value:299 // key:0 value:1 key:2 value:77 key:10 value:81 key:2 value:88 key:4 value:93 key:3 value:101 key:10 value:105 key:2 value:111 key:4 value:115 key:3 value:122 key:10 value:126 key:2 value:132 key:4 value:136 key:3 value:143 key:3 value:150 key:1 value:299
``` ```
### getDepth ### getDepth
...@@ -543,7 +536,7 @@ getDepth(): number ...@@ -543,7 +536,7 @@ getDepth(): number
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -555,20 +548,16 @@ let strXml = ...@@ -555,20 +548,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.getDepth() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getDepth();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:0key:2 value:1key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:3 value:1key:1 value:0 // key:0 value:0 key:2 value:1 key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 key:10 value:1 key:2 value:2 key:4 value:2 key:3 value:2 key:3 value:1 key:1 value:0
// 解析: // 解析:
// key代表了当前事件类型,value为当前解析的深度。你可以根据EVENTTYPE来知道具体的解析事件。例如本示例结果key: value代表含义为: // key代表了当前事件类型,value为当前解析的深度。你可以根据EVENTTYPE来知道具体的解析事件。例如本示例结果key: value代表含义为:
// 0(START_DOCUMENT):0(起始深度为0), 2(START_TAG):1(解析到开始标签node, 对应深度为1), 10(WHITESPACE):1(解析到空白标签空格, 对应深度为1), 2(START_TAG):2(解析到开始标签title, 对应深度为2), ... // 0(START_DOCUMENT):0(起始深度为0), 2(START_TAG):1(解析到开始标签node, 对应深度为1), 10(WHITESPACE):1(解析到空白标签空格, 对应深度为1), 2(START_TAG):2(解析到开始标签title, 对应深度为2), ...
...@@ -590,7 +579,7 @@ getLineNumber(): number ...@@ -590,7 +579,7 @@ getLineNumber(): number
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -602,20 +591,16 @@ let strXml = ...@@ -602,20 +591,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.getLineNumber() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getLineNumber();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:1key:2 value:1key:10 value:1key:2 value:1key:4 value:1key:3 value:1key:10 value:1key:2 value:1key:4 value:1key:3 value:1key:10 value:1key:2 value:1key:4 value:1key:3 value:1key:3 value:1key:1 value:1 // key:0 value:1 key:2 value:1 key:10 value:1 key:2 value:1 key:4 value:1 key:3 value:1 key:10 value:1 key:2 value:1 key:4 value:1 key:3 value:1 key:10 value:1 key:2 value:1 key:4 value:1 key:3 value:1 key:3 value:1 key:1 value:1
``` ```
### getName ### getName
...@@ -634,7 +619,7 @@ getName(): string ...@@ -634,7 +619,7 @@ getName(): string
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -646,20 +631,16 @@ let strXml = ...@@ -646,20 +631,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.getName() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getName();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:key:2 value:notekey:10 value:key:2 value:titlekey:4 value:key:3 value:titlekey:10 value:key:2 value:todokey:4 value:key:3 value:todokey:10 value:key:2 value:todokey:4 value:key:3 value:todokey:3 value:notekey:1 value: // key:0 value: key:2 value:note key:10 value: key:2 value:title key:4 value: key:3 value:title key:10 value: key:2 value:todo key:4 value: key:3 value:todo key:10 value: key:2 value:todo key:4 value: key:3 value:todo key:3 value:note key:1 value:
``` ```
### getNamespace ### getNamespace
...@@ -677,7 +658,7 @@ getNamespace(): string ...@@ -677,7 +658,7 @@ getNamespace(): string
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -689,20 +670,16 @@ let strXml = ...@@ -689,20 +670,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.getNamespace() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getNamespace();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:key:2 value:key:10 value:key:2 value:key:4 value:key:3 value:key:10 value:key:2 value:key:4 value:key:3 value:key:10 value:key:2 value:key:4 value:key:3 value:key:3 value:key:1 value: // key:0 value: key:2 value: key:10 value: key:2 value: key:4 value: key:3 value: key:10 value: key:2 value: key:4 value: key:3 value: key:10 value: key:2 value: key:4 value: key:3 value: key:3 value: key:1 value:
``` ```
### getPrefix ### getPrefix
...@@ -720,7 +697,7 @@ getPrefix(): string ...@@ -720,7 +697,7 @@ getPrefix(): string
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -732,20 +709,16 @@ let strXml = ...@@ -732,20 +709,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.getPrefix() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getPrefix();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:key:2 value:key:10 value:key:2 value:key:4 value:key:3 value:key:10 value:key:2 value:key:4 value:key:3 value:key:10 value:key:2 value:key:4 value:key:3 value:key:3 value:key:1 value: // key:0 value: key:2 value: key:10 value: key:2 value: key:4 value: key:3 value: key:10 value: key:2 value: key:4 value: key:3 value: key:10 value: key:2 value: key:4 value: key:3 value: key:3 value: key:1 value:
``` ```
### getText ### getText
...@@ -764,7 +737,7 @@ getText(): string ...@@ -764,7 +737,7 @@ getText(): string
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -776,20 +749,16 @@ let strXml = ...@@ -776,20 +749,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += ' key:' + key + ' value:' + value.getText() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getText();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:key:2 value:key:10 value: key:2 value:key:4 value:Happykey:3 value:key:10 value: key:2 value:key:4 value:Workkey:3 value:key:10 value: key:2 value:key:4 value:Playkey:3 value:key:3 value:key:1 value: // key:0 value: key:2 value: key:10 value: key:2 value: key:4 value:Happy key:3 value: key:10 value: key:2 value: key:4 value:Work key:3 value: key:10 value: key:2 value: key:4 value:Play key:3 value: key:3 value: key:1 value:
``` ```
### isEmptyElementTag ### isEmptyElementTag
...@@ -807,7 +776,7 @@ isEmptyElementTag(): boolean ...@@ -807,7 +776,7 @@ isEmptyElementTag(): boolean
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -819,20 +788,16 @@ let strXml = ...@@ -819,20 +788,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.isEmptyElementTag() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.isEmptyElementTag();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:falsekey:2 value:falsekey:10 value:falsekey:2 value:falsekey:4 value:falsekey:3 value:falsekey:10 value:falsekey:2 value:falsekey:4 value:falsekey:3 value:falsekey:10 value:falsekey:2 value:falsekey:4 value:falsekey:3 value:falsekey:3 value:falsekey:1 value:false // key:0 value:false key:2 value:false key:10 value:false key:2 value:false key:4 value:false key:3 value:false key:10 value:false key:2 value:false key:4 value:false key:3 value:false key:10 value:false key:2 value:false key:4 value:false key:3 value:false key:3 value:false key:1 value:false
``` ```
### isWhitespace ### isWhitespace
...@@ -850,7 +815,7 @@ isWhitespace(): boolean ...@@ -850,7 +815,7 @@ isWhitespace(): boolean
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -862,20 +827,16 @@ let strXml = ...@@ -862,20 +827,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.isWhitespace() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.isWhitespace();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:truekey:2 value:falsekey:10 value:truekey:2 value:truekey:4 value:falsekey:3 value:truekey:10 value:truekey:2 value:truekey:4 value:falsekey:3 value:truekey:10 value:truekey:2 value:truekey:4 value:falsekey:3 value:truekey:3 value:truekey:1 value:true // key:0 value:true key:2 value:false key:10 value:true key:2 value:true key:4 value:false key:3 value:true key:10 value:true key:2 value:true key:4 value:false key:3 value:true key:10 value:true key:2 value:true key:4 value:false key:3 value:true key:3 value:true key:1 value:true
``` ```
### getAttributeCount ### getAttributeCount
...@@ -892,7 +853,7 @@ getAttributeCount(): number ...@@ -892,7 +853,7 @@ getAttributeCount(): number
**示例:** **示例:**
```js ```ts
import util from '@ohos.util'; import util from '@ohos.util';
let strXml = let strXml =
'<?xml version="1.0" encoding="utf-8"?>' + '<?xml version="1.0" encoding="utf-8"?>' +
...@@ -904,20 +865,16 @@ let strXml = ...@@ -904,20 +865,16 @@ let strXml =
let textEncoder = new util.TextEncoder(); let textEncoder = new util.TextEncoder();
let arrbuffer = textEncoder.encodeInto(strXml); let arrbuffer = textEncoder.encodeInto(strXml);
let that = new xml.XmlPullParser(arrbuffer.buffer); let that = new xml.XmlPullParser(arrbuffer.buffer);
let arrTag = {};
let str = ""; let str = "";
let i = 0; function func(key: xml.EventType, value: xml.ParseInfo) {
function func(key, value){ str += 'key:' + key + ' value:' + value.getAttributeCount() + ' ';
arrTag[i] = 'key:'+key+' value:'+ value.getAttributeCount();
str += arrTag[i];
i++;
return true; // Determines whether to continually parse, which is used to continue or terminate parsing. return true; // Determines whether to continually parse, which is used to continue or terminate parsing.
} }
let options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} let options: xml.ParseOptions = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func}
that.parse(options); that.parse(options);
console.log(str); console.log(str);
// 输出: // 输出:
// key:0 value:0key:2 value:2key:10 value:0key:2 value:0key:4 value:0key:3 value:0key:10 value:0key:2 value:0key:4 value:0key:3 value:0key:10 value:0key:2 value:0key:4 value:0key:3 value:0key:3 value:0key:1 value:0 // key:0 value:0 key:2 value:2 key:10 value:0 key:2 value:0 key:4 value:0 key:3 value:0 key:10 value:0 key:2 value:0 key:4 value:0 key:3 value:0 key:10 value:0 key:2 value:0 key:4 value:0 key:3 value:0 key:3 value:0 key:1 value:0
``` ```
## EventType ## EventType
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册