• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { ColumnOperation } from '../components/ColumnOperation';
17import { serializerNode, parserNode, convertNode } from '../util/ConvertXmlUtil';
18
19@Component
20export struct ConvertXml {
21  @State output: string = `eTSXmlTextConvert`;
22  @State input: string =
23    `<?xml version="1.0" encoding="utf-8"?>
24     <note importance="high" logged="true">
25         <title>Happy</title>
26         <todo>Work</todo>
27         <todo>Play</todo>
28     </note>`;
29
30  build() {
31    Scroll() {
32      Column() {
33        Text(this.output)
34          .width('90%')
35          .height('60%')
36          .fontSize(15)
37          .padding(10)
38          .margin({ left: 10, right: 10, top: 20, bottom: 10 })
39          .border({ width: 2, radius: 5, color: Color.Gray })
40        ColumnOperation({ operationRes: $r('app.strarray.convert_xml_operations'), doOperation: this.doOperation })
41      }
42      .width('100%')
43      .padding(16)
44    }
45    .scrollBar(BarState.Off)
46    .align(Alignment.Start)
47  }
48
49  doOperation = (index: number) => {
50    switch (index) {
51      case 0:
52        this.output = serializerNode();
53        break;
54      case 1:
55        this.output = parserNode(this.input);
56        break;
57      case 2:
58        this.output = convertNode(this.input);
59        break;
60      default:
61        break;
62    }
63  }
64}