Работа над XmlParser

This commit is contained in:
Book Pauk
2022-11-08 16:12:46 +07:00
parent 9cf9530447
commit f7994fd9e9

View File

@@ -228,7 +228,7 @@ class XmlParser extends NodeBase {
return this.rawNodes.length; return this.rawNodes.length;
} }
toObject(node) { nodeObject(node) {
return new NodeObject(node); return new NodeObject(node);
} }
@@ -335,14 +335,20 @@ class XmlParser extends NodeBase {
} }
} else { } else {
for (const n of this.rawNodes) { for (const n of this.rawNodes) {
if (n[0] === NODE && n[3]) if (n[0] === NODE && n[3]) {
callback(new NodeObject(n[3])); for (const nn of n[3])
callback(new NodeObject(nn));
}
} }
} }
return this; return this;
} }
eachSelf(callback) {
return this.each(callback, true);
}
eachDeep(callback, self = false) { eachDeep(callback, self = false) {
const deep = (nodes, route = '') => { const deep = (nodes, route = '') => {
for (const n of nodes) { for (const n of nodes) {
@@ -423,7 +429,7 @@ class XmlParser extends NodeBase {
selectFirst(selector, self) { selectFirst(selector, self) {
const result = this.select(selector, self); const result = this.select(selector, self);
const node = (result.count ? result.rawNodes[0] : null); const node = (result.count ? result.rawNodes[0] : null);
return this.toObject(node); return new NodeObject(node);
} }
$(selector, self) { $(selector, self) {
@@ -452,7 +458,12 @@ class XmlParser extends NodeBase {
} }
toString(options = {}) { 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 deepType = 0;
let out = ''; let out = '';
@@ -545,7 +556,7 @@ class XmlParser extends NodeBase {
return; return;
if (!ignoreNode && pickNode) { if (!ignoreNode && pickNode) {
route += `/${tag}`; route += `${route ? '/' : ''}${tag}`;
ignoreNode = !pickNode(route); ignoreNode = !pickNode(route);
} }