未验证 提交 48c8a7ba 编写于 作者: O openharmony_ci 提交者: Gitee

!10313 【轻量级 PR】:update zh-cn/application-dev/faqs/faqs-ui-js.md.

Merge pull request !10313 from zengyawen/N/A
......@@ -13,8 +13,8 @@ convertxml中convert方法提供了转换xml文本为JavaScript对象的能力
```
import convertxml from '@ohos.convertxml';
// 代码片段
xml =
// xml格式的字符串
let xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
......@@ -23,15 +23,23 @@ xml =
'</note>';
let conv = new convertxml.ConvertXML();
// 转换选项, 参考文档使用
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:any = conv.convert(xml, options) // 将xml文本转为JS对象
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: any = conv.convert(xml, options) // 将xml文本转为JS对象
console.log('Test: ' + JSON.stringify(result))
console.log('Test: ' + result._declaration._attributes.version) // xml代码片段version字段信息
console.log('Test: ' + result._elements[0]._elements[0]._elements[0]._text) // xml代码片段title字段内容
console.log('Test: ' + result._declaration._attributes.version) // xml字符串中version字段信息console.log('Test: ' + result._elements[0]._elements[0]._elements[0]._text) // xml字符串中title字段内容
```
参考文档:[xml转换JavaScript](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-convertxml.md)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册