@Shuan- Thanks a lot!
On Thu, Feb 13, 2014 at 1:42 AM, Shuan Wang <shuanw...@gmail.com> wrote: > Hello Anurag > > The actual value is stored properly but for display purposes are not shown > past the 2nd level. This is because by default console.log/util.inspect > only goes 2 levels deep. If you want to see deeper into your Object you > need to pass in a parameter to util.inspect > > So instead of `console.log(object)` you need to instead do > `console.log(util.inspect(object, { depth: 3 }))` where 3 is the number of > levels deep you want to display. > > More information here: > http://nodejs.org/api/util.html#util_util_inspect_object_options > > > On Wednesday, February 12, 2014 9:04:14 AM UTC-8, Anurag Prasad wrote: > >> I am getting the wrong output here. Instead of [Object] something like >> {name : "weight", type: "integer", value: "32"} should be the output. >> >> [ { group: 'nodes', data: { id: '1', label: 'A', att: [Object] } }, >> { group: 'nodes', data: { id: '2', label: 'B', att: [Object] } }, >> { group: 'nodes', data: { id: '3', label: 'C', att: [Object] } }, >> { group: 'edges', >> data: { label: 'A-B', source: '1', target: '2', att: [Object] } }, >> { group: 'edges', >> data: { label: 'B-C', source: '2', target: '3', att: [Object] } }, >> { group: 'edges', >> data: { label: 'C-A', source: '3', target: '1', att: [Object] } } ] >> >> Kindly help me out with this. >> >> >> On Wed, Feb 12, 2014 at 1:47 AM, Anurag Prasad <apras...@gmail.com>wrote: >> >>> Thanks. JSHint was great. A number of problems in the code were fixed. >>> The code is running now. >>> >>> >>> On Wed, Feb 12, 2014 at 1:44 AM, Jeremy Darling <jeremy....@gmail.com>wrote: >>> >>>> As others have already said, you should be using a linter/hinter on >>>> your source code. There are a lot of bad habits in your code and those >>>> make it easy for you to have this type of mistake. >>>> >>>> If you use proper indention, and remove those unnecessary ;'s you can >>>> spot your problem very quickly. >>>> >>>> Here is your bad code: >>>> >>>> parser.onopentag = function(node) { >>>> // opened a tag. node has "name" and "attributes" >>>> if (node.name == 'node') { >>>> nodeCounter++; >>>> elements_array.push({ >>>> group: 'nodes', >>>> data: { id: node.attributes.id, label: node.attributes.label } >>>> }); >>>> >>>> if (node.name == 'edge') { >>>> nodeCounter++; >>>> elements_array.push({ >>>> group: 'edges', >>>> data: { label: node.attributes.label, source: >>>> node.attributes.source, target: node.attributes.target } >>>> }); >>>> >>>> if (node.name =='att') { >>>> var key = node.attributes.name; >>>> elements_array[nodeCounter].data.key = { type : >>>> node.attributes.type, value: node.attributes.value}; >>>> } >>>> } >>>> } >>>> >>>> >>>> Notice that you are missing a }; at the end of your code. So lets >>>> clean it up a bit more and fix the code itself. >>>> >>>> >>>> parser.onopentag = function(node) { >>>> // opened a tag. node has "name" and "attributes" >>>> if (node.name == 'node') { >>>> nodeCounter++; >>>> elements_array.push({ >>>> group: 'nodes', >>>> data: { >>>> id: node.attributes.id, >>>> label: node.attributes.label >>>> } >>>> }); >>>> >>>> if (node.name == 'edge') { >>>> nodeCounter++; >>>> elements_array.push({ >>>> group: 'edges', >>>> data: { >>>> label: node.attributes.label, >>>> source: node.attributes.source, >>>> target: node.attributes.target >>>> } >>>> }); >>>> >>>> if (node.name =='att') { >>>> var key = node.attributes.name; >>>> elements_array[nodeCounter].data.key = { >>>> type : node.attributes.type, >>>> value: node.attributes.value >>>> }; >>>> } >>>> } >>>> } >>>> }; >>>> >>>> >>>> On Tue, Feb 11, 2014 at 2:03 PM, Anurag Prasad <apras...@gmail.com>wrote: >>>> >>>>> I am still not able to figure out what the problem is. >>>>> >>>>> >>>>> On Wed, Feb 12, 2014 at 12:48 AM, Diogo Resende < >>>>> dres...@thinkdigital.pt> wrote: >>>>> >>>>>> Your “Code” part does not seem to have any problems, at least a >>>>>> missing “)”. You should really install a linter in your editor, you have >>>>>> unused vars and global pollution.. >>>>>> >>>>>> -- >>>>>> Diogo Resende >>>>>> >>>>>> On Tuesday 11 February 2014 at 19:14 , Anurag Prasad wrote: >>>>>> >>>>>> [image: Inline image 1] >>>>>> >>>>>> >>>>>> *Code->* >>>>>> >>>>>> var fs = require('fs'); >>>>>> var sax = require('sax'); >>>>>> >>>>>> parser = sax.parser(true); >>>>>> >>>>>> elements_array = []; >>>>>> nodeCounter = -1; >>>>>> >>>>>> parser.onerror = function(e) { >>>>>> // an error happened. >>>>>> }; >>>>>> >>>>>> parser.onopentag = function(node) { >>>>>> // opened a tag. node has "name" and "attributes" >>>>>> if (node.name == 'node') { >>>>>> nodeCounter++; >>>>>> elements_array.push({ >>>>>> group: 'nodes', >>>>>> data: { id: node.attributes.id, label: node.attributes.label } >>>>>> }); >>>>>> >>>>>> if (node.name == 'edge') { >>>>>> nodeCounter++; >>>>>> elements_array.push({ >>>>>> group: 'edges', >>>>>> data: { label: node.attributes.label, source: >>>>>> node.attributes.source, target: node.attributes.target } >>>>>> }); >>>>>> >>>>>> if (node.name =='att') { >>>>>> var key = node.attributes.name; >>>>>> elements_array[nodeCounter].data.key = { type : >>>>>> node.attributes.type, value: node.attributes.value}; >>>>>> }; >>>>>> }; >>>>>> >>>>>> }; >>>>>> >>>>>> parser.onend = function() { >>>>>> // parser stream is done, and ready to have more stuff written to >>>>>> it. >>>>>> console.log("XML has been parsed.\n"); >>>>>> }; >>>>>> >>>>>> >>>>>> try { >>>>>> var file_buf = fs.readFileSync('./graph.xml'); >>>>>> parser.write(file_buf.toString('utf8')).close(); >>>>>> } catch(ex) { >>>>>> // keep 'em silent >>>>>> } >>>>>> >>>>>> console.log(elements_array); >>>>>> >>>>>> -- >>>>>> -- >>>>>> Job Board: http://jobs.nodejs.org/ >>>>>> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List- >>>>>> Posting-Guidelines >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "nodejs" group. >>>>>> To post to this group, send email to nod...@googlegroups.com >>>>>> >>>>>> To unsubscribe from this group, send email to >>>>>> nodejs+un...@googlegroups.com >>>>>> >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/nodejs?hl=en?hl=en >>>>>> >>>>>> --- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "nodejs" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>> send an email to nodejs+un...@googlegroups.com. >>>>>> >>>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>>> >>>>>> >>>>>> -- >>>>>> -- >>>>>> Job Board: http://jobs.nodejs.org/ >>>>>> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List- >>>>>> Posting-Guidelines >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "nodejs" group. >>>>>> To post to this group, send email to nod...@googlegroups.com >>>>>> >>>>>> To unsubscribe from this group, send email to >>>>>> nodejs+un...@googlegroups.com >>>>>> >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/nodejs?hl=en?hl=en >>>>>> >>>>>> --- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "nodejs" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>> send an email to nodejs+un...@googlegroups.com. >>>>>> >>>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Anurag Prasad >>>>> Birla Institute of Technology & Science, Pilani >>>>> Pilani Campus >>>>> Pilani, India. 333 031 >>>>> Mobile: +91 - 9001250705 >>>>> E.mail: f201...@pilani.bits-pilani.ac.in >>>>> www.bits-pilani.ac.in >>>>> >>>>> -- >>>>> -- >>>>> Job Board: http://jobs.nodejs.org/ >>>>> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List- >>>>> Posting-Guidelines >>>>> You received this message because you are subscribed to the Google >>>>> Groups "nodejs" group. >>>>> To post to this group, send email to nod...@googlegroups.com >>>>> >>>>> To unsubscribe from this group, send email to >>>>> nodejs+un...@googlegroups.com >>>>> >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/nodejs?hl=en?hl=en >>>>> >>>>> --- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "nodejs" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to nodejs+un...@googlegroups.com. >>>>> >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>> >>>> -- >>>> -- >>>> Job Board: http://jobs.nodejs.org/ >>>> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List- >>>> Posting-Guidelines >>>> You received this message because you are subscribed to the Google >>>> Groups "nodejs" group. >>>> To post to this group, send email to nod...@googlegroups.com >>>> >>>> To unsubscribe from this group, send email to >>>> nodejs+un...@googlegroups.com >>>> >>>> For more options, visit this group at >>>> http://groups.google.com/group/nodejs?hl=en?hl=en >>>> >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "nodejs" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to nodejs+un...@googlegroups.com. >>>> >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>> >>> >>> >>> -- >>> Anurag Prasad >>> Birla Institute of Technology & Science, Pilani >>> Pilani Campus >>> Pilani, India. 333 031 >>> Mobile: +91 - 9001250705 >>> E.mail: f201...@pilani.bits-pilani.ac.in >>> www.bits-pilani.ac.in >>> >> >> >> >> -- >> Anurag Prasad >> Birla Institute of Technology & Science, Pilani >> Pilani Campus >> Pilani, India. 333 031 >> Mobile: +91 - 9001250705 >> E.mail: f201...@pilani.bits-pilani.ac.in >> www.bits-pilani.ac.in >> > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com > To unsubscribe from this group, send email to > nodejs+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to nodejs+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- Anurag Prasad Birla Institute of Technology & Science, Pilani Pilani Campus Pilani, India. 333 031 Mobile: +91 - 9001250705 E.mail: f2011...@pilani.bits-pilani.ac.in www.bits-pilani.ac.in -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.