1/* 2 * Copyright (c) 2021-2022 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 16/** 17 * The convertxml module provides utilities for converting XML text to Javascript object. 18 * @since 8 19 * @syscap SystemCapability.Utils.Lang 20 * @permission N/A 21 */ 22declare namespace xml { 23 interface ConvertOptions { 24 /** 25 * Whether to trim whitespace characters that may exist before and after the text, default false. 26 * @since 8 27 * @syscap SystemCapability.Utils.Lang 28 */ 29 trim: boolean; 30 /** 31 * Whether to ignore writing declaration directives of xml. 32 * @since 8 33 * @syscap SystemCapability.Utils.Lang 34 */ 35 ignoreDeclaration?: boolean; 36 /** 37 * Whether to ignore writing processing instruction of xml. 38 * @since 8 39 * @syscap SystemCapability.Utils.Lang 40 */ 41 ignoreInstruction?: boolean; 42 /** 43 * Whether to print attributes across multiple lines and indent them. 44 * @since 8 45 * @syscap SystemCapability.Utils.Lang 46 */ 47 ignoreAttributes?: boolean; 48 /** 49 * Whether to ignore writing comments of the elements. 50 * @since 8 51 * @syscap SystemCapability.Utils.Lang 52 */ 53 ignoreComment?: boolean; 54 /** 55 * Whether to ignore writing CDATA of the elements. 56 * @since 8 57 * @syscap SystemCapability.Utils.Lang 58 */ 59 ignoreCDATA?: boolean; 60 /** 61 * Whether to ignore writing Doctype of the elements. 62 * @since 8 63 * @syscap SystemCapability.Utils.Lang 64 */ 65 ignoreDoctype?: boolean; 66 /** 67 * Whether to ignore writing texts of the elements. 68 * @since 8 69 * @syscap SystemCapability.Utils.Lang 70 */ 71 ignoreText?: boolean; 72 /** 73 * Name of the property key which will be used for the declaration. 74 * @since 8 75 * @syscap SystemCapability.Utils.Lang 76 */ 77 declarationKey: string; 78 /** 79 * Name of the property key which will be used for the processing instruction. 80 * @since 8 81 * @syscap SystemCapability.Utils.Lang 82 */ 83 instructionKey: string; 84 /** 85 * Name of the property key which will be used for the attributes. 86 * @since 8 87 * @syscap SystemCapability.Utils.Lang 88 */ 89 attributesKey: string; 90 /** 91 * Name of the property key which will be used for the text. 92 * @since 8 93 * @syscap SystemCapability.Utils.Lang 94 */ 95 textKey: string; 96 /** 97 * Name of the property key which will be used for the cdata. 98 * @since 8 99 * @syscap SystemCapability.Utils.Lang 100 */ 101 cdataKey: string; 102 /** 103 * Name of the property key which will be used for the doctype. 104 * @since 8 105 * @syscap SystemCapability.Utils.Lang 106 */ 107 doctypeKey: string; 108 /** 109 * Name of the property key which will be used for the comment. 110 * @since 8 111 * @syscap SystemCapability.Utils.Lang 112 */ 113 commentKey: string; 114 /** 115 * Name of the property key which will be used for the parent. 116 * @since 8 117 * @syscap SystemCapability.Utils.Lang 118 */ 119 parentKey: string; 120 /** 121 * Name of the property key which will be used for the type. 122 * @since 8 123 * @syscap SystemCapability.Utils.Lang 124 */ 125 typeKey: string; 126 /** 127 * Name of the property key which will be used for the name. 128 * @since 8 129 * @syscap SystemCapability.Utils.Lang 130 */ 131 nameKey: string; 132 /** 133 * Name of the property key which will be used for the elements. 134 * @since 8 135 * @syscap SystemCapability.Utils.Lang 136 */ 137 elementsKey: string; 138 } 139 140 /** 141 * ConvertXML representation refers to extensible markup language. 142 * @name ConvertXML 143 * @since 8 144 * @syscap SystemCapability.Utils.Lang 145 */ 146 class ConvertXML { 147 /** 148 * To convert XML text to JavaScript object. 149 * @since 8 150 * @deprecated since 9 151 * @useinstead ohos.convertxml.ConvertXML.convertToJSObject 152 * @syscap SystemCapability.Utils.Lang 153 * @param xml The xml text to be converted. 154 * @param option Option Inputted by user to set. 155 * @returns Returns a JavaScript object converting from XML text. 156 */ 157 convert(xml: string, options?: ConvertOptions) : Object; 158 159 /** 160 * To convert XML text to JavaScript object. 161 * @since 9 162 * @syscap SystemCapability.Utils.Lang 163 * @param xml The xml text to be converted. 164 * @param option Option Inputted by user to set. 165 * @returns Returns a JavaScript object converting from XML text. 166 * @throws {BusinessError} 401 - if the input parameters are invalid. 167 * @throws {BusinessError} 10200002 - Invalid xml string. 168 */ 169 convertToJSObject(xml: string, options?: ConvertOptions) : Object; 170 } 171} 172export default xml;