Browse Source

Работа над XmlParser

Book Pauk 2 years ago
parent
commit
28963116c3
1 changed files with 23 additions and 10 deletions
  1. 23 10
      server/core/xml/XmlParser.js

+ 23 - 10
server/core/xml/XmlParser.js

@@ -186,7 +186,8 @@ class NodeObject extends NodeBase {
             return;
             return;
 
 
         for (const n of this.raw[3]) {
         for (const n of this.raw[3]) {
-            callback(new NodeObject(n));
+            if (callback(new NodeObject(n)) === false)
+                break;
         }
         }
 
 
         return this;
         return this;
@@ -199,10 +200,13 @@ class NodeObject extends NodeBase {
         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);
+
+                if (callback(node, route) === false)
+                    return false;
 
 
                 if (node.type === NODE && node.value) {
                 if (node.type === NODE && node.value) {
-                    deep(node.value, `${route}${route ? '/' : ''}${node.name}`);
+                    if (deep(node.value, `${route}${route ? '/' : ''}${node.name}`) === false)
+                        return false;
                 }
                 }
             }
             }
         }
         }
@@ -332,13 +336,15 @@ class XmlParser extends NodeBase {
     each(callback, self = false) {
     each(callback, self = false) {
         if (self) {
         if (self) {
             for (const n of this.rawNodes) {
             for (const n of this.rawNodes) {
-                callback(new NodeObject(n));
+                if (callback(new NodeObject(n)) === false);
+                    return this;
             }
             }
         } 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]) {
                     for (const nn of n[3])
                     for (const nn of n[3])
-                        callback(new NodeObject(nn));
+                        if (callback(new NodeObject(nn)) === false)
+                            return this;
                 }
                 }
             }
             }
         }
         }
@@ -354,10 +360,13 @@ class XmlParser extends NodeBase {
         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);
+
+                if (callback(node, route) === false)
+                    return false;
 
 
                 if (node.type === NODE && node.value) {
                 if (node.type === NODE && node.value) {
-                    deep(node.value, `${route}${route ? '/' : ''}${node.name}`);
+                    if (deep(node.value, `${route}${route ? '/' : ''}${node.name}`) === false)
+                        return false;
                 }
                 }
             }
             }
         }
         }
@@ -367,7 +376,8 @@ 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])
-                    deep(n[3]);
+                    if (deep(n[3]) === false)
+                        break;
             }
             }
         }
         }
 
 
@@ -750,8 +760,11 @@ class XmlParser extends NodeBase {
         return this;
         return this;
     }
     }
 
 
-    navigator() {
-        return new ObjectNavigator(this.toObject());
+    navigator(obj) {
+        if (!obj)
+            obj = this.toObject();
+
+        return new ObjectNavigator(obj);
     }
     }
 }
 }