• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ArkTS Subsystem Changelog
2
3## cl.arkts.1 convertXml Now Supports parentKey
4
5**Access Level**
6
7Public API
8
9**Reason for Change**
10
11The convertXml module does not support the **parentKey** attribute. The generated object does not contain the **parentKey** attribute value.
12
13**Change Impact**
14
15This change is a non-compatible change.
16
17Before change:
18
19When **convertToJSObject** parses the input parameters of an XML string, setting the **parentKey** attribute value is not supported.
20
21After change:
22
23When **convertToJSObject** parses the input parameters of an XML string, setting the **parentKey** attribute value is supported.
24
25**Start API Level**
26
279
28
29**Change Since**
30
31OpenHarmony SDK 5.0.1.1
32
33**Key API/Component Changes**
34
35API in the convertXML module:
36
37convertToJSObject(xml: string, options?: ConvertOptions): Object;
38
39**Adaptation Guide**
40
41No adaptation is required.
42
43```ts
44import { convertxml } from '@kit.ArkTS';
45
46let xml =
47  '<?xml version="1.0" encoding="utf-8"?>' +
48    '<note importance="high" logged="true">' +
49    '    <title>Happy</title>' +
50    '    <todo>Work</todo>' +
51    '    <todo>Play</todo>' +
52    '</note>';
53let conv = new convertxml.ConvertXML()
54let options: convertxml.ConvertOptions = {
55  trim: false,
56  declarationKey: "_declaration",
57  instructionKey: "_instruction",
58  attributesKey: "_attributes",
59  textKey: "_text",
60  cdataKey: "_cdata",
61  doctypeKey: "_doctype",
62  commentKey: "_comment",
63  parentKey: "_parent",
64  typeKey: "_type",
65  nameKey: "_name",
66  elementsKey: "_elements"
67}
68let result: ESObject = conv.convertToJSObject(xml, options);
69
70// Before the change, the value of result is {"_declaration":{"_attributes":{"version":"1.0","encoding":"utf-8"}},"_elements":[{"_type":"element","_name":"note","_attributes":{"importance":"high","logged":"true"},"_elements":[{"_type":"element","_name":"title","_elements":[{"_type":"text","_text":"Happy"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Work"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Play"}]}]}]}.
71
72// After the change, the value of result is {"_declaration":{"_attributes":{"version":"1.0","encoding":"utf-8"}},"_elements":[{"_type":"element","_name":"note","_attributes":{"importance":"high","logged":"true"},"_elements":[{"_type":"element","_name":"title","_parent":"note","_elements":[{"_type":"text","_text":"Happy"}]},{"_type":"element","_name":"todo","_parent":"note","_elements":[{"_type":"text","_text":"Work"}]},{"_type":"element","_name":"todo","_parent":"note","_elements":[{"_type":"text","_text":"Play"}]}]}]}. (The parentKey attribute value is added.)
73
74// This does not affect the API usage.
75// To obtain the parentKey attribute of the title tag, call the following API: result1["_elements"][0]["_elements"][0]._parent
76// Before change: The parentKey attribute of the title tag is undefined.
77// After change: The parentKey attribute of the title tag is the actual value note.
78```
79
80## cl.arkts.2 Encoding Behavior of utf-16le and utf-16be of the util.TextEncoder Module Changed
81
82**Access Level**
83
84Public API
85
86**Reason for Change**
87
88When TextEncoder uses the utf-16le or utf-16be encoding format, the encoded data obtained is incorrect.
89
90The utf-16le encoding format uses little-endian. However, the encoded data is in big-endian format.
91
92The utf-16be encoding format uses big-endian. However, the encoded data is in little-endian format.
93
94The data obtained does not comply with the standard definition. This problem needs to be corrected.
95
96**Change Impact**
97
98This change is a non-compatible change.
99
100Before change:
101
102- The utf-16le encoding format uses little-endian. However, the encoded data is in big-endian format.
103- The utf-16be encoding format uses big-endian. However, the encoded data is in little-endian format.
104
105After change:
106
107- The utf-16le encoding format uses little-endian, and the encoded data is in little-endian format.
108- The utf-16be encoding format uses big-endian, and the encoded data is in big-endian format.
109
110**Start API Level**
111
1129
113
114**Change Since**
115
116OpenHarmony SDK 5.0.1.1
117
118**Key API/Component Changes**
119
120APIs of the util.TextEncoder module:
121
122encodeInto(input?: string): Uint8Array;
123
124encodeIntoUint8Array(input: string, dest: Uint8Array): EncodeIntoUint8ArrayInfo;
125
126**Adaptation Guide**
127
128No adaptation is required.
129
130Behavior of **encodeInto**:
131
132```ts
133import { util } from '@kit.ArkTS';
134
135let encoderUtf16Le = new util.TextEncoder("utf-16le");
136let encoderUtf16Be = new util.TextEncoder("utf-16be");
137
138// Before change:
139// let u8_le = encoderUtf16Le.encodeInto('abcdefg'); // u8_le: 0,97,0,98,0,99,0,100,0,101,0,102,0,103
140// let u8_be = encoderUtf16Be.encodeInto('abcdefg'); // u8_be: 97,0,98,0,99,0,100,0,101,0,102,0,103,0
141
142
143// After change:
144let u8_le = encoderUtf16Le.encodeInto('abcdefg'); // u8_le: 97,0,98,0,99,0,100,0,101,0,102,0,103,0
145let u8_be = encoderUtf16Be.encodeInto('abcdefg'); // u8_be: 0,97,0,98,0,99,0,100,0,101,0,102,0,103
146```
147
148Behavior of **encodeIntoUint8Array**:
149
150```ts
151import { util } from '@kit.ArkTS';
152
153let encoderUtf16Le = new util.TextEncoder("utf-16le");
154let encoderUtf16Be = new util.TextEncoder("utf-16be");
155
156// Before change:
157// let dest_le = new Uint8Array(14);
158// let dest_be = new Uint8Array(14);
159// let res_le = encoderUtf16Le.encodeIntoUint8Array('abcdefg', dest_le); // dest_le: 0,97,0,98,0,99,0,100,0,101,0,102,0,103
160// let res_be = encoderUtf16Be.encodeIntoUint8Array('abcdefg', dest_be); // dest_be: 97,0,98,0,99,0,100,0,101,0,102,0,103,0
161
162// After change:
163let dest_le = new Uint8Array(14);
164let dest_be = new Uint8Array(14);
165let res_le = encoderUtf16Le.encodeIntoUint8Array('abcdefg', dest_le); // dest_le: 97,0,98,0,99,0,100,0,101,0,102,0,103,0
166let res_be = encoderUtf16Be.encodeIntoUint8Array('abcdefg', dest_be); // dest_be: 0,97,0,98,0,99,0,100,0,101,0,102,0,103
167```
168