From 04a8ba8426e571cb2d47b3774faec83770551a5f Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Wed, 9 Nov 2022 14:44:00 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20XmlParser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/xml/XmlParser.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/server/core/xml/XmlParser.js b/server/core/xml/XmlParser.js index a24cd2d..fedc362 100644 --- a/server/core/xml/XmlParser.js +++ b/server/core/xml/XmlParser.js @@ -455,6 +455,8 @@ class XmlParser extends NodeBase { throw new Error('JSON parse error: root element must be array'); this.rawNodes = parsed; + + return this; } toString(options = {}) { @@ -641,9 +643,15 @@ class XmlParser extends NodeBase { }); this.rawNodes = parsed; + + return this; } - toObject() { + toObject(options = {}) { + const { + compactText = false + } = options; + const nodesToObject = (nodes) => { const result = {}; @@ -663,8 +671,9 @@ class XmlParser extends NodeBase { if (node.value) { Object.assign(newNode, nodesToObject(node.value)); - //схлопывание узла до строки - if (!Array.isArray(newNode) + //схлопывание текстового узла до string + if (compactText + && !Array.isArray(newNode) && Object.prototype.hasOwnProperty.call(newNode, '*TEXT') && Object.keys(newNode).length === 1) { newNode = newNode['*TEXT']; @@ -736,6 +745,8 @@ class XmlParser extends NodeBase { }; this.rawNodes = objectToNodes(xmlObject); + + return this; } }