XML : Parsing XML in Node through node-xml2js

So I have a XML file containing the following:

  <?xml version="1.0" encoding="UTF-8" ?>  <_id>4699066</_id>  <name>Houston</name>  <country>US</country>  <coord>      <lon>-95.363274</lon>      <lat>29.763281</lat>  </coord>    

And the following JS

  fs.readFile(__dirname + '/HoustonUS.xml', function(err, data){    parser.parseString(data, function(err,result){      console.log(result);    });    });    

I am using these technologies in GitHub Electron and every time I run the app the console prints 'undefined' for where the result should be printed.How will I be able to print every element in the XML for the sake of debugging purposes and assign each XML element to its own variable?

No comments:

Post a Comment