Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
by (120 points)
I am trying to parse XML file nodes.I am able to print whole xml file to console but i am trying to get the values of internal nodes.

Any suggestions are appreciated

1 Answer

0 votes
by (44.4k points)

Use this GitHub repo to get the code - This is the node parser js file of AWS javascript sdk. To test, you can use this 

'use strict';

var xml2js = require('xml2js');

console.log('Loading function');

var options = {  // options passed to xml2js parser

  explicitCharkey: false, // undocumented

  trim: false,            // trim the leading/trailing whitespace from text nodes

  normalize: false,       // trim interior whitespace inside text nodes

  explicitRoot: false,    // return the root node in the resulting object?

  emptyTag: null,         // the default value for empty nodes

  explicitArray: true,    // always put child nodes in an array

  ignoreAttrs: false,     // ignore attributes, only create text nodes

  mergeAttrs: false,      // merge attributes and child elements

  validator: null         // a callable validator


exports.handler = (event, context, callback) => {

    var parser = new xml2js.Parser(options);

    //console.log('Received event:', JSON.stringify(event, null, 2));

    console.log('value1 =', event.key1);

    console.log('value2 =', event.key2);

    console.log('value3 =', event.key3);

    callback(null, event.key1);  // Echo back the first key value

    //callback('Something went wrong');


Browse Categories