Работа над XmlParser

This commit is contained in:
Book Pauk
2022-11-08 14:42:28 +07:00
parent e755ddbbef
commit 98fac2bf11

View File

@@ -201,7 +201,7 @@ class NodeObject extends NodeBase {
callback(node, route); callback(node, route);
if (node.type === NODE && node.value) { if (node.type === NODE && node.value) {
deep(node.value, route + `/${node.name}`); deep(node.value, `${route}${route ? '/' : ''}${node.name}`);
} }
} }
} }
@@ -328,31 +328,49 @@ class XmlParser extends NodeBase {
return this; return this;
} }
each(callback) { each(callback, self = false) {
for (const n of this.rawNodes) { if (self) {
callback(new NodeObject(n)); for (const n of this.rawNodes) {
callback(new NodeObject(n));
}
} else {
for (const n of this.rawNodes) {
if (n[0] === NODE && n[3])
callback(new NodeObject(n[3]));
}
} }
return this; return this;
} }
eachDeep(callback) { eachDeep(callback, self = false) {
const deep = (nodes, route = '') => { const deep = (nodes, route = '') => {
for (const n of nodes) { for (const n of nodes) {
const node = new NodeObject(n); const node = new NodeObject(n);
callback(node, route); callback(node, route);
if (node.type === NODE && node.value) { if (node.type === NODE && node.value) {
deep(node.value, route + `/${node.name}`); deep(node.value, `${route}${route ? '/' : ''}${node.name}`);
} }
} }
} }
deep(this.rawNodes); if (self) {
deep(this.rawNodes);
} else {
for (const n of this.rawNodes) {
if (n[0] === NODE && n[3])
deep(n[3]);
}
}
return this; return this;
} }
eachDeepSelf(callback) {
return this.eachDeep(callback, true);
}
rawSelect(nodes, selectorObj, callback) { rawSelect(nodes, selectorObj, callback) {
for (const n of nodes) for (const n of nodes)
if (this.checkNode(n, selectorObj)) if (this.checkNode(n, selectorObj))