From 48de82a8cfc5579ae32e043f096e76e45708f89a Mon Sep 17 00:00:00 2001 From: lihucheng Date: Wed, 7 Sep 2022 17:03:01 +0800 Subject: [PATCH] Rectification XML and convertxml guidance documents 1.Add output 2.Add notes issue: Signed-off-by: lihucheng --- .../reference/apis/js-apis-convertxml.md | 2 ++ en/application-dev/reference/apis/js-apis-xml.md | 13 ++++++++++--- .../reference/apis/js-apis-convertxml.md | 4 +++- zh-cn/application-dev/reference/apis/js-apis-xml.md | 13 ++++++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-convertxml.md b/en/application-dev/reference/apis/js-apis-convertxml.md index 43e096b951..82941689b8 100644 --- a/en/application-dev/reference/apis/js-apis-convertxml.md +++ b/en/application-dev/reference/apis/js-apis-convertxml.md @@ -56,6 +56,8 @@ let options = {trim : false, declarationKey:"_declaration", nameKey : "_name", elementsKey : "_elements"} let result = JSON.stringify(conv.convert(xml, options)); console.log(result) +// Output(Non compact) +// {"_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"}]}]}]} ``` ## ConvertOptions diff --git a/en/application-dev/reference/apis/js-apis-xml.md b/en/application-dev/reference/apis/js-apis-xml.md index 21e43edc10..c7d28fe1bf 100644 --- a/en/application-dev/reference/apis/js-apis-xml.md +++ b/en/application-dev/reference/apis/js-apis-xml.md @@ -344,15 +344,22 @@ for (var i = 0; i < strLen; ++i) { } var that = new xml.XmlPullParser(arrayBuffer); var arrTag = {}; -arrTag[0] = '132'; -var i = 1; +var str = ""; +var i = 0; function func(key, value){ arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); + str += arrTag[i]; i++; - return true; + return true; // Determines whether to continuely parse, which is used to continue or terminate parsing. } var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} that.parse(options); +console.log(str); +// Output: +// key:0 value:0key:2 value:1key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:3 value:1key:1 value:0 +// Notes: +// The key represents the current event type, and the value represents the depth of the current parsing. You can know the parsed event according to EVENTTYPE. For example, the result 'key: value' in this example means: +// 0(START_DOCUMENT):0(Parse to the START_DOCUMENT, and the depth is 0), 2(START_TAG):1(Parse to the START_TAG node, and the depth is 1), 10(WHITESPACE):1(Parse to the WHITESPACE space, and the depth is 1), 2(START_TAG):2(Parse to the START_TAG title, and the depth is 2), ... ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-convertxml.md b/zh-cn/application-dev/reference/apis/js-apis-convertxml.md index cbb605b604..ec0549cfff 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-convertxml.md +++ b/zh-cn/application-dev/reference/apis/js-apis-convertxml.md @@ -54,7 +54,9 @@ let options = {trim : false, declarationKey:"_declaration", commentKey : "_comment", parentKey : "_parent", typeKey : "_type", nameKey : "_name", elementsKey : "_elements"} let result = JSON.stringify(conv.convert(xml, options)); -console.log(result) +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"}]}]}]} ``` ## ConvertOptions diff --git a/zh-cn/application-dev/reference/apis/js-apis-xml.md b/zh-cn/application-dev/reference/apis/js-apis-xml.md index 412412d1c5..f33be6b32f 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-xml.md +++ b/zh-cn/application-dev/reference/apis/js-apis-xml.md @@ -343,15 +343,22 @@ for (var i = 0; i < strLen; ++i) { } var that = new xml.XmlPullParser(arrayBuffer); var arrTag = {}; -arrTag[0] = '132'; -var i = 1; +var str = ""; +var i = 0; function func(key, value){ arrTag[i] = 'key:'+key+' value:'+ value.getDepth(); + str += arrTag[i]; i++; - return true; + return true; // Determines whether to continuely parse, which is used to continue or terminate parsing. } var options = {supportDoctype:true, ignoreNameSpace:true, tokenValueCallbackFunction:func} that.parse(options); +console.log(str); +// 输出: +// key:0 value:0key:2 value:1key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:10 value:1key:2 value:2key:4 value:2key:3 value:2key:3 value:1key:1 value:0 +// 解析: +// key代表了当前事件类型,value为当前解析的深度。你可以根据EVENTTYPE来知道具体的解析事件。例如本示例结果key: value代表含义为: +// 0(START_DOCUMENT):0(起始深度为0), 2(START_TAG):1(解析到开始标签node, 对应深度为1), 10(WHITESPACE):1(解析到空白标签空格, 对应深度为1), 2(START_TAG):2(解析到开始标签title, 对应深度为1), ... ``` -- GitLab