提交 43c30c26 编写于 作者: J jiangkai43 提交者: Jiang

Description of adding new interfaces

https://gitee.com/openharmony/docs/issues/I5X82BSigned-off-by: Njiangkai43 <jiangkai43@huawei.com>
上级 e60f7304
......@@ -14,8 +14,53 @@ import convertxml from '@ohos.convertxml';
## ConvertXML
### convertToJSObject<sup>9+</sup>
### convert
convertToJSObject(xml: string, options?: ConvertOptions) : Object
转换xml文本为JavaScript对象。
**系统能力:** SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | --------------------------------- | ---- | --------------- |
| xml | string | 是 | 传入的xml文本。 |
| options | [ConvertOptions](#convertoptions) | 否 | 转换选项。 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------- |
| Object | 处理后返回的JavaScript对象。 |
**示例:**
```js
let xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
let conv = new convertxml.convertToJSObject();
let options = {trim : false, declarationKey:"_declaration",
instructionKey : "_instruction", attributesKey : "_attributes",
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
commentKey : "_comment", parentKey : "_parent", typeKey : "_type",
nameKey : "_name", elementsKey : "_elements"}
let result = JSON.stringify(conv.convert(xml, options));
console.log(result);
// 输出(宽泛型)
// {"_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"}]}]}]}
```
### convert<sup>(deprecated)</sup>
> **说明:**<br/>
> 从API Version 9开始废弃,建议使用[convertToJSObject9+](#converttojsobject9)替代。
convert(xml: string, options?: ConvertOptions) : Object
......@@ -23,7 +68,6 @@ convert(xml: string, options?: ConvertOptions) : Object
**系统能力:** SystemCapability.Utils.Lang
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册