瀏覽代碼

Changement lib sax

Loquicom 5 年之前
父節點
當前提交
9ce7d6350a
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7 5
      src/parser/parser.js

+ 7 - 5
src/parser/parser.js

@@ -1,3 +1,4 @@
+const Saxophone = require('saxophone');
 const file = require('../file');
 
 const ROOT_TAG = 'dblp';
@@ -24,10 +25,10 @@ const parser = class Parser {
         this.callback = null;
         this.source = null;
         this.dest = null;
-        this.sax = require('sax').createStream(true);
+        this.sax = new Saxophone();
         this.sax.on('error', this._error);
-        this.sax.on('opentag', this._opentag);
-        this.sax.on('closetag', this._closetag);
+        this.sax.on('tagopen', this._opentag);
+        this.sax.on('tagclose', this._closetag);
         this.sax.on('text', this._text);
     }
 
@@ -47,7 +48,7 @@ const parser = class Parser {
             }
         }
         this.callback = callback;
-        file.fs.createReadStream(this.source).pipe(this.sax);
+        file.fs.createReadStream(this.source, {start: 77}).pipe(this.sax);
     }
 
     from(source) {
@@ -84,6 +85,7 @@ const parser = class Parser {
     }
 
     _closetag(tag) {
+        tag = tag.name;
         if (tag === ROOT_TAG && instance.callback !== null) {
             instance.callback(instance.dest);
         } else if (instance._inTag && instance._tag === tag) {
@@ -99,7 +101,7 @@ const parser = class Parser {
 
     _text(text) {
         if (instance._isAuth) {
-            instance._auth.push(text);
+            instance._auth.push(text.contents);
         }
     }