From f7994fd9e95de076d432e1e9a4eb0f4ff913590f Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Tue, 8 Nov 2022 16:12:46 +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 | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/server/core/xml/XmlParser.js b/server/core/xml/XmlParser.js index bca3160..8591e85 100644 --- a/server/core/xml/XmlParser.js +++ b/server/core/xml/XmlParser.js @@ -228,7 +228,7 @@ class XmlParser extends NodeBase { return this.rawNodes.length; } - toObject(node) { + nodeObject(node) { return new NodeObject(node); } @@ -335,14 +335,20 @@ class XmlParser extends NodeBase { } } else { for (const n of this.rawNodes) { - if (n[0] === NODE && n[3]) - callback(new NodeObject(n[3])); + if (n[0] === NODE && n[3]) { + for (const nn of n[3]) + callback(new NodeObject(nn)); + } } } return this; } + eachSelf(callback) { + return this.each(callback, true); + } + eachDeep(callback, self = false) { const deep = (nodes, route = '') => { for (const n of nodes) { @@ -423,7 +429,7 @@ class XmlParser extends NodeBase { selectFirst(selector, self) { const result = this.select(selector, self); const node = (result.count ? result.rawNodes[0] : null); - return this.toObject(node); + return new NodeObject(node); } $(selector, self) { @@ -452,7 +458,12 @@ class XmlParser extends NodeBase { } toString(options = {}) { - const {encoding = 'utf-8', format = false, noHeader = false, expandEmpty = false} = options; + const { + encoding = 'utf-8', + format = false, + noHeader = false, + expandEmpty = false + } = options; let deepType = 0; let out = ''; @@ -545,7 +556,7 @@ class XmlParser extends NodeBase { return; if (!ignoreNode && pickNode) { - route += `/${tag}`; + route += `${route ? '/' : ''}${tag}`; ignoreNode = !pickNode(route); }