Jatinder Singh Jatinder Singh - 1 year ago 64
JSON Question

How to remove attribute from xml node?

I have an xml which I have to convert to Json. The xml has nodes like

<Title xml:lang="en">The Steal In The Wheels</Title>


I want to remove this
xml:lang="en"
from the xml nodes.

Actually, I am working in node.js and I need title value. I am converting XML to Json using xml2js. It is converting to json but it is giving title value with style. So that i am trying to remove this attribute.

Any help appreciated

Thanks in advance!

Answer Source

I was converting xml to json and when i was trying to get the value of title then it was coming with style.

So that i asked this question. Now i got the solution so that i want to share with you if anybody from you stucked like me then it will help you.

Here is the code:

var xml2js = require('xml2js');

function GetRequestBody(data){

    var parser = new xml2js.Parser({ignoreAttrs : true, mergeAttrs : false});
    parser.parseString(data.toString(), function (err, result) {
    var post_data = querystring.stringify({
                      'name' : result.Documents.Content[0].Title 
                  });

     return post_data;
    });
} 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download