2016-04-18 20 views
0

ライブラリxml2jsを使用したいと思います。私はnpmでプロジェクトフォルダにインストールします。要求が定義されていませんxml2js

var parseString = require('xml2js').parseString; 
var xml = "<root>Hello xml2js!</root>"; 
parseString.(xml, function (err, result) { 
    console.dir(result); 
}); 

私はノードmyfile.jsを実行し、エラーを持っている:

d:\Profiles\user\ProjectIDE\Aproject\parseXML.js:3 
parseString.(xml, function (err, result) { 
      ^

SyntaxError: Unexpected token (
    at exports.runInThisContext (vm.js:53:16) 
    at Module._compile (module.js:373:25) 
    at Object.Module._extensions..js (module.js:416:10) 
    at Module.load (module.js:343:32) 
    at Function.Module._load (module.js:300:12) 
    at Function.Module.runMain (module.js:441:10) 
    at startup (node.js:139:18) 
    at node.js:968:3 

答えて

0

構文エラー:この代わりの

parseString.(xml, function (err, result) { 
    console.dir(result); 
}); 

はこれを試してみてください

parseString(xml, function (err, result) { 
    console.dir(result); 
}); 
0

これは私のために働いた:

var xml2js = require('xml2js'); 
    var parser = new xml2js.Parser(); 
    // var util = require('util'); 

    parser.parseString(xml, function(err, result){ 
     console.log(result); 
     // In case you want to see the whole thing. 
     // console.log(util.inspect(result, {showHidden:true, depth:null}); 
    }); 
関連する問題